working_final

This commit is contained in:
2021-11-10 18:03:02 +01:00
parent f75c487484
commit d566487d3a

View File

@@ -1,13 +1,14 @@
import csv import csv
from datetime import datetime from datetime import datetime
import sys import sys
import pandas as pd
FILE = 'TMGDSP202105.CSV' FILE = 'TMGDSP202105.CSV'
#usrmonth = input("Month to be processed: ") #usrmonth = input("Month to be processed: ")
countofnotsms = int(1) countofnotsms = int(1)
countofsms = 0
dictionary = {} dictionary = {}
@@ -67,7 +68,6 @@ with open(FILE, newline='', encoding='utf-8') as csvfile:
MSISDN = int(row['MSISDN']) MSISDN = int(row['MSISDN'])
ICCID = int(row['ICCID']) ICCID = int(row['ICCID'])
price = float(row['CHARGE_NET'].replace(',','.')) price = float(row['CHARGE_NET'].replace(',','.'))
@@ -93,17 +93,18 @@ with open(FILE, newline='', encoding='utf-8') as csvfile:
if row['INCREMENT'] == "SMS": if row['INCREMENT'] == "SMS":
pricesms = int(row['RATED_AMOUNT']) pricesms = int(row['RATED_AMOUNT'])
print("catched SMS increment col") else:
pricesms = 0
#only if not exist create new record in dictionary for ID #only if not exist create new record in dictionary for ID
if not MSISDN in dictionary: if not MSISDN in dictionary:
dictionary[MSISDN] = {'ICCID':ICCID,'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':0} dictionary[MSISDN] = {'ICCID':ICCID,'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':pricesms}
else: else:
print("Adding: ",price," for: ", dictionary[MSISDN], "TYP: ",typ) print("Adding: ",price," for: ", dictionary[MSISDN], "TYP: ",typ)
if row['INCREMENT'] == "SMS": if row['INCREMENT'] == "SMS":
print("pricesms: ",pricesms) print("pricesms: ",pricesms," for unit: ",dictionary[MSISDN])
add_dict2(MSISDN, pricesms) add_dict2(MSISDN, pricesms)
add_dict(MSISDN, typ, price) add_dict(MSISDN, typ, price)
@@ -134,3 +135,18 @@ print("Count of units: ", len(dictionary.keys()))
# print(key,dictionary[key]) # print(key,dictionary[key])
# f.write("%s,%s\n"%(key,dictionary[key])) # f.write("%s,%s\n"%(key,dictionary[key]))
csv_columns = ['takhleuztoneudelam', 'ICCID', 'data', 'sms', 'other', 'smscount']
try:
with open('fakturace_tmgdsp_export_20211110v3.csv', 'w') as csvfile:
w = csv.DictWriter(sys.stdout, csv_columns)
for key, val in sorted(dictionary.items()):
row = {'takhleuztoneudelam': key}
row.update(val)
writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
writer.writerow(row)
except IOError:
print(f"I/O error: {IOError}")