Merge does pair the serial number

This commit is contained in:
2022-08-22 00:46:17 +02:00
parent 4920315ad6
commit 0eb420add2

64
main.py
View File

@@ -32,6 +32,8 @@ def merge():
vfczfile = [filename for filename in os.listdir(dirpath) if filename.startswith("output_VFCZ_")]
vfczfile = vfczfile[0]
# Help dicts
# tmcz_convertids
convert_tmcz = {}
with open('./help_files/TMCZ_IMSI.csv', 'r') as file:
@@ -42,6 +44,41 @@ def merge():
print(row['IMSI'])
convert_tmcz[MSISDN] = {'iccid': row['ICCID'],'imsi': row['IMSI']}
# kranggulo_config_ids
serialnumberdict = {}
with open('./help_files/config_parser.csv', 'r') as file:
reader =csv.DictReader(file, delimiter=',')
for row in reader:
intobuid = int(row['obuid'])
date = row['date']
realsn = row['SN']
IMEI = int(row['IMEI'])
IMSI = int(row['IMSI'])
CCID = int(row['CCID'])
if IMSI in serialnumberdict:
print("dict for IMSI: ",IMSI,"dict: ",serialnumberdict[IMSI])
olddate = serialnumberdict[IMSI]['date']
if date > olddate:
print("editovat, tento zaznam je novejsi")
print("mame: ", olddate)
print("zpracovavame: ", date)
serialnumberdict[IMSI]['date'] = date
serialnumberdict[IMSI]['obuid'] = intobuid
serialnumberdict[IMSI]['sn'] = realsn
serialnumberdict[IMSI]['imei'] = IMEI
serialnumberdict[IMSI]['ccid'] = CCID
print(serialnumberdict[IMSI])
else:
print("needitovat, tento zaznam je starsi")
print("mame: ",olddate)
print("zpracovavame: ",date)
else:
serialnumberdict[IMSI] = {'obuid':intobuid,'date': date,'sn': realsn,'imei': IMEI,'ccid': CCID}
@@ -52,7 +89,7 @@ def merge():
reader = csv.DictReader(csvfile, delimiter=',')
#next(reader)
print("got into reader func")
with open('./help_files/output_testmerge.csv', 'w', newline='', encoding="utf-8") as f:
with open('./output/output_testmerge.csv', 'w', newline='', encoding="utf-8") as f:
writer = csv.writer(f)
for row in reader:
@@ -67,10 +104,30 @@ def merge():
imsi = convert_tmcz[msisdn]['imsi']
imsitoconvert = int(imsi)
#print(serialnumberdict[int(imsitoconvert)]['sn'])
if imsitoconvert in serialnumberdict:
print("found in snhelper, can convert to sn")
realsn = serialnumberdict[int(imsitoconvert)]['sn']
print(realsn)
else:
print("not found in helper, cannot convert to sn")
realsn = "unknown"
else:
print("msisdn not found in helper, we dont have iccid and imsi")
iccid = "N/A"
imsi = "N/A"
realsn = "unknown"
dataprice = row['DATA-PRICE']
dataamount = row['DATA-AMOUNT']
@@ -79,7 +136,8 @@ def merge():
otherprice = row['OTHER-PRICE']
simstatus = row['SIM-STATUS']
operator = row['OPERATOR']
writer.writerow([msisdn, iccid, imsi, dataprice, dataamount, smsprice, smscount, otherprice, simstatus, operator])
print("realsn: ",realsn)
writer.writerow([msisdn, iccid, imsi, dataprice, dataamount, smsprice, smscount, otherprice, simstatus, realsn, operator])
print("Merged")
with open(dirpath+vfczfile, newline='', encoding="utf-8") as csvfile:
@@ -137,6 +195,8 @@ def merge():
operator = row['OPERATOR']
writer.writerow([msisdn, iccid, imsi, dataprice, dataamount, smsprice, smscount, otherprice, simstatus, operator])
print("succesfuly merged")
def checkFiles():