working_final
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import csv
|
||||
from datetime import datetime
|
||||
import sys
|
||||
import pandas as pd
|
||||
|
||||
FILE = 'TMGDSP202105.CSV'
|
||||
|
||||
#usrmonth = input("Month to be processed: ")
|
||||
|
||||
countofnotsms = int(1)
|
||||
countofsms = 0
|
||||
|
||||
|
||||
dictionary = {}
|
||||
|
||||
@@ -67,7 +68,6 @@ with open(FILE, newline='', encoding='utf-8') as csvfile:
|
||||
|
||||
|
||||
|
||||
|
||||
MSISDN = int(row['MSISDN'])
|
||||
ICCID = int(row['ICCID'])
|
||||
price = float(row['CHARGE_NET'].replace(',','.'))
|
||||
@@ -93,17 +93,18 @@ with open(FILE, newline='', encoding='utf-8') as csvfile:
|
||||
if row['INCREMENT'] == "SMS":
|
||||
|
||||
pricesms = int(row['RATED_AMOUNT'])
|
||||
print("catched SMS increment col")
|
||||
else:
|
||||
pricesms = 0
|
||||
|
||||
#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}
|
||||
dictionary[MSISDN] = {'ICCID':ICCID,'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':pricesms}
|
||||
|
||||
|
||||
else:
|
||||
print("Adding: ",price," for: ", dictionary[MSISDN], "TYP: ",typ)
|
||||
if row['INCREMENT'] == "SMS":
|
||||
print("pricesms: ",pricesms)
|
||||
print("pricesms: ",pricesms," for unit: ",dictionary[MSISDN])
|
||||
add_dict2(MSISDN, pricesms)
|
||||
add_dict(MSISDN, typ, price)
|
||||
|
||||
@@ -134,3 +135,18 @@ print("Count of units: ", len(dictionary.keys()))
|
||||
# print(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}")
|
||||
|
||||
Reference in New Issue
Block a user