init
This commit is contained in:
136
ucetnictvi_pokusy.py
Normal file
136
ucetnictvi_pokusy.py
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
import csv
|
||||||
|
from datetime import datetime
|
||||||
|
import sys
|
||||||
|
|
||||||
|
FILE = 'TMGDSP202105.CSV'
|
||||||
|
|
||||||
|
#usrmonth = input("Month to be processed: ")
|
||||||
|
|
||||||
|
countofnotsms = int(1)
|
||||||
|
countofsms = 0
|
||||||
|
|
||||||
|
dictionary = {}
|
||||||
|
|
||||||
|
def add_dict(id, key, value):
|
||||||
|
dict = dictionary.get(id)
|
||||||
|
if key in dict:
|
||||||
|
print("increasing dict key for: ",value,"key IS: ",key)
|
||||||
|
dict[key] += value
|
||||||
|
|
||||||
|
print("end state: ",dict[key])
|
||||||
|
dict[key] = round(dict[key],5)
|
||||||
|
print("key: ",key)
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Never should happen", id)
|
||||||
|
|
||||||
|
def add_dict2(id, pricesms):
|
||||||
|
dict = dictionary.get(id)
|
||||||
|
|
||||||
|
print("increasing dict key for: ",pricesms)
|
||||||
|
dict["smscount"] += pricesms
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#MAIN
|
||||||
|
with open(FILE, newline='', encoding='utf-8') as csvfile:
|
||||||
|
reader = csv.DictReader(csvfile, delimiter=';')
|
||||||
|
for row in reader:
|
||||||
|
|
||||||
|
#print(row)
|
||||||
|
if row['MSISDN'] == '':
|
||||||
|
continue #skip empty MSISDN
|
||||||
|
|
||||||
|
#if row['BILLED_PERIOD_START'] == '':
|
||||||
|
#continue
|
||||||
|
|
||||||
|
#my_string = row['BILLED_PERIOD_START']
|
||||||
|
#my_string = '2021-09-06'
|
||||||
|
#print(my_string)
|
||||||
|
#try:
|
||||||
|
#my_date = datetime.strptime(my_string, "%Y-%m-%d")
|
||||||
|
#except:
|
||||||
|
#print("An exception occurred, current my_string is: ", my_string)
|
||||||
|
#sys.exit(1)
|
||||||
|
|
||||||
|
#print(row['BILLED_PERIOD_START'])
|
||||||
|
#print(my_date.month)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if my_date.month != '5':
|
||||||
|
#continue #skip bad dates
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MSISDN = int(row['MSISDN'])
|
||||||
|
ICCID = int(row['ICCID'])
|
||||||
|
price = float(row['CHARGE_NET'].replace(',','.'))
|
||||||
|
|
||||||
|
price = round(price, 5)
|
||||||
|
|
||||||
|
|
||||||
|
typ = None
|
||||||
|
if row['CHARGE_TYPE'] == "Pravidelné měsíční poplatky":
|
||||||
|
typ = "data"
|
||||||
|
elif row['CHARGE_TYPE'] == "Poplatky za roamingový datový provoz":
|
||||||
|
typ = "data"
|
||||||
|
elif row['CHARGE_TYPE'] == "Poplatky za národní datový provoz":
|
||||||
|
typ = "data"
|
||||||
|
elif row['CHARGE_TYPE'] == "Poplatky za roamingový SMS provoz":
|
||||||
|
typ = "sms"
|
||||||
|
elif row['CHARGE_TYPE'] == "Poplatky za národní SMS provoz":
|
||||||
|
typ = "sms"
|
||||||
|
else:
|
||||||
|
typ = 'other'
|
||||||
|
|
||||||
|
|
||||||
|
if row['INCREMENT'] == "SMS":
|
||||||
|
|
||||||
|
pricesms = int(row['RATED_AMOUNT'])
|
||||||
|
print("catched SMS increment col")
|
||||||
|
|
||||||
|
#only if not exist create new record in dictionary for ID
|
||||||
|
if not MSISDN in dictionary:
|
||||||
|
dictionary[MSISDN] = {'ICCID':ICCID,'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':0}
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Adding: ",price," for: ", dictionary[MSISDN], "TYP: ",typ)
|
||||||
|
if row['INCREMENT'] == "SMS":
|
||||||
|
print("pricesms: ",pricesms)
|
||||||
|
add_dict2(MSISDN, pricesms)
|
||||||
|
add_dict(MSISDN, typ, price)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ptry:
|
||||||
|
#print(dictionary[436761890319959]) #one with both types
|
||||||
|
#pexcept:
|
||||||
|
#pprint("Required unit is not in our set")
|
||||||
|
#psys.exit(1)
|
||||||
|
|
||||||
|
#pprint(len(dictionary.keys()))
|
||||||
|
|
||||||
|
#for key, value in dictionary.items():
|
||||||
|
#print(key, ' : ', value)
|
||||||
|
|
||||||
|
|
||||||
|
print("Count of units: ", len(dictionary.keys()))
|
||||||
|
#print("Count of sms: ",countofsms)
|
||||||
|
#for dict_value in dictionary:
|
||||||
|
# type(dict_value)
|
||||||
|
# #for k, v in dict_value.items():
|
||||||
|
|
||||||
|
|
||||||
|
#with open('fakturace_tmgdsp_export_20211110v2.csv', 'w') as f:
|
||||||
|
# for key in dictionary.keys():
|
||||||
|
# print(key,dictionary[key])
|
||||||
|
# f.write("%s,%s\n"%(key,dictionary[key]))
|
||||||
|
|
||||||
Reference in New Issue
Block a user