diff --git a/ucetnictvi_tm.py b/ucetnictvi_tm.py index 4788b8a..fb0224e 100644 --- a/ucetnictvi_tm.py +++ b/ucetnictvi_tm.py @@ -41,6 +41,12 @@ def add_dictsms(id, pricesms): print("increasing sms dict key for dict: ",dict," for :",pricesms) dict["smscount"] += pricesms +def add_dictdataamount(id, dataamount): + dict = dictionary.get(id) + + print("increasing dataamount dict key for dict: ",dict," for :",dataamount) + dict["dataamount"] += dataamount + #MAIN print("Start") @@ -111,8 +117,6 @@ with open(FILE, newline='', encoding="utf-8") as csvfile: else: typ = 'other' - - if row['Jednotka'] == "ks": pricesms = int(row['Počet jednotek – volné']) + int(row['Počet jednotek – účtované']) @@ -121,11 +125,21 @@ with open(FILE, newline='', encoding="utf-8") as csvfile: else: pricesms = 0 - + + if row['Jednotka'] == "kB": + + dataamount = (int(row['Počet jednotek – volné']) + int(row['Počet jednotek – účtované'])) / 1024 + print("rowjednotka: ",row['Jednotka']) + print("sms price: ",pricesms,MSISDN) + + else: + dataamount = 0 + + #only if not exist create new record in dictionary for ID if not MSISDN in dictionary: print("Creating dictionary: ", MSISDN) - dictionary[MSISDN] = {'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':pricesms} + dictionary[MSISDN] = {'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':pricesms, 'dataamount':dataamount} if price != '': print("Editing dictionary: ", MSISDN, "typ: ", typ, "cena: ", price) @@ -133,9 +147,11 @@ with open(FILE, newline='', encoding="utf-8") as csvfile: add_dict(MSISDN, typ, price) if row['Jednotka'] == "ks": - #print("pricesms: ", pricesms, " for unit: ", dictionary[MSISDN]) + add_dictsms(MSISDN, pricesms) + if row['Jednotka'] == "kB": + add_dictdataamount(MSISDN, dataamount) #try: @@ -165,11 +181,12 @@ with open('output_TMCZ_'+ext_date_from_filaname, 'w') as f: sms = dictionary[key]['sms'] other = dictionary[key]['other'] smscount = dictionary[key]['smscount'] + dataamount = dictionary[key]['dataamount'] - writer.writerow([key, "N/A", "N/A", data, "N/A", sms, "N/A", other, "N/A"]) + writer.writerow([key, "N/A", "N/A", data, dataamount, sms, smscount, other, "N/A"])