1015 lines
34 KiB
Python
1015 lines
34 KiB
Python
import tkinter as tk
|
|
|
|
from tkinter import ttk
|
|
import subprocess as sp
|
|
import sys
|
|
import os
|
|
from tkinter import messagebox
|
|
import pandas as pd
|
|
import glob
|
|
import urllib.request
|
|
import csv
|
|
from datetime import datetime
|
|
import time
|
|
import configparser
|
|
from pandastable import Table
|
|
import pathlib
|
|
import cnb_exchange_rate
|
|
from tktooltip import ToolTip
|
|
|
|
ver = "0.5.2"
|
|
|
|
outvar = {}
|
|
|
|
def convertExcelToCSV():
|
|
print("Converting Excel to CSV")
|
|
files = glob.glob("*.xlsx")
|
|
for f in files:
|
|
print(f)
|
|
df = pd.read_excel(f)
|
|
df.to_csv(f.replace(".xlsx", ".csv"), index=False)
|
|
os.remove(f)
|
|
print("Done")
|
|
|
|
def getCNBRates():
|
|
current_month = datetime.now().strftime('%m')
|
|
current_year_full = datetime.now().strftime('%Y')
|
|
rate = cnb_exchange_rate.daily_rate('EUR', datetime(2022, 12, 1))
|
|
return rate
|
|
|
|
getCNBRates()
|
|
|
|
|
|
def updateapp():
|
|
print("Updating app")
|
|
ret = sp.call(["python", "update.py"])
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
def convertChars(val):
|
|
converted = val.replace(',', '')
|
|
converted = converted.replace('.', ',')
|
|
return converted
|
|
def doNothing():
|
|
print("")
|
|
def test():
|
|
config = configparser.ConfigParser()
|
|
config.read('config.conf')
|
|
|
|
|
|
tmgdspen = tk.IntVar()
|
|
vfgdspen = tk.IntVar()
|
|
tmczen = tk.IntVar()
|
|
vfczen = tk.IntVar()
|
|
|
|
tmgdspen.set(int(1))
|
|
vfgdspen.set(int(0))
|
|
tmczen.set(int(0))
|
|
vfczen.set(int(1))
|
|
print(tmczen.get())
|
|
print("test")
|
|
|
|
|
|
|
|
def openConfig():
|
|
|
|
#configwindow = tk.Toplevel(root)
|
|
configwindow = tk.Tk()
|
|
configwindow.title("Config")
|
|
configwindow.geometry("320x150")
|
|
|
|
|
|
config = configparser.ConfigParser()
|
|
config.read('config.conf')
|
|
|
|
|
|
tmgdspen = tk.IntVar()
|
|
vfgdspen = tk.IntVar()
|
|
tmczen = tk.IntVar()
|
|
vfczen = tk.IntVar()
|
|
|
|
jedna.set(int(config.get('modules', 'tmgdsp')))
|
|
dva.set(int(config.get('modules', 'vfgdsp')))
|
|
tri.set(int(config.get('modules', 'tmcz')))
|
|
ctyri.set(int(config.get('modules', 'vfcz')))
|
|
|
|
|
|
checktmgdsp = tk.Checkbutton(configwindow, text="TMGDSP", variable=tmgdspen, onvalue=1, offvalue=0)
|
|
checkvfgdsp = tk.Checkbutton(configwindow, text="VFGDSP", variable=vfgdspen, onvalue=1, offvalue=0)
|
|
checktmcz = tk.Checkbutton(configwindow, text="TMCZ", variable=tmczen, onvalue=1, offvalue=0)
|
|
checkvfcz = tk.Checkbutton(configwindow, text="VFCZ", variable=vfczen, onvalue=1, offvalue=0)
|
|
|
|
|
|
|
|
checktmgdsp.place(x=10, y=10)
|
|
checkvfgdsp.place(x=10, y=30)
|
|
checkvfcz.place(x=10, y=50)
|
|
checktmcz.place(x=10, y=70)
|
|
btn = tk.Button(configwindow, text='Save',command=lambda: test(), width=20)
|
|
|
|
|
|
btn.place(x=50, y=90)
|
|
configwindow.after(0,configwindow.update())
|
|
|
|
|
|
def buttonnewwindow():
|
|
newwindow = tk.Toplevel(root)
|
|
newwindow.title("CSV")
|
|
newwindow.geometry("1000x700")
|
|
frame = tk.Frame(newwindow)
|
|
frame.pack(fill='both', expand=1)
|
|
|
|
table = Table(frame,showtoolbar=True, showstatusbar=True)
|
|
|
|
|
|
|
|
table.show()
|
|
dirpath = "output/"
|
|
mergedfile = [filename for filename in os.listdir(dirpath) if filename.startswith("merged_output_")]
|
|
print('mergedfile: ',mergedfile[0])
|
|
table.importCSV('output/'+mergedfile[0])
|
|
#table.setColumnColors(cols=[1, 2], clr='green')
|
|
#table.colheader.cellwidth = 100
|
|
|
|
|
|
def realsndatestrip(realsndate):
|
|
d = datetime.strptime(realsndate, "%Y-%m-%d %H:%M:%S")
|
|
realsndate = d.strftime("%d-%m-%Y")
|
|
return realsndate
|
|
|
|
|
|
def pairBis():
|
|
bisbyphoneno = {}
|
|
bisbyiccid = {}
|
|
completepairing = {}
|
|
# create two help dicts for pairing
|
|
# first one is for pairing by Phone No., second one is for pairing by ICCID
|
|
dirpath = "./help_files/"
|
|
bispairingfile = [filename for filename in os.listdir(dirpath) if filename.startswith("bis")]
|
|
with open('./help_files/' + bispairingfile[0], 'r',encoding='utf-8') as file:
|
|
reader =csv.DictReader(file, delimiter=';')
|
|
for row in reader:
|
|
|
|
# do we have valid Phone number for this record?
|
|
if row['Phone No.'] != '' and row['Phone No.'] != 'True' and row['Phone No.'] != 'False':
|
|
phoneno = int(row['Phone No.'])
|
|
|
|
amount = row['Amount']
|
|
currency = row['Currency']
|
|
code = row['Code']
|
|
textid = row['Text ID']
|
|
iccid = row['ICCID']
|
|
print("iccid: ",iccid)
|
|
print("phoneno: ", phoneno)
|
|
MU_ID = row['MU ID']
|
|
if phoneno == 882390031032318:
|
|
print("found")
|
|
sys.exit()
|
|
|
|
bisbyphoneno[phoneno] = {'amount': amount, 'currency': currency, 'code': code, 'textid': textid, 'mu_id': MU_ID}
|
|
|
|
# We don't have valid Phone number, so we use ICCID if possible
|
|
elif row['ICCID'] != '' and row['ICCID'] != 'True' and row['ICCID'] != 'False':
|
|
|
|
print("We have no Phone number, trying to pair by iccid")
|
|
iccid = row['ICCID']
|
|
MU_ID = row['MU ID']
|
|
phoneno = 0
|
|
amount = row['Amount']
|
|
currency = row['Currency']
|
|
code = row['Code']
|
|
textid = row['Text ID']
|
|
print("iccid: ", iccid)
|
|
print("phoneno: ", phoneno)
|
|
bisbyiccid[iccid] = {'amount': amount, 'currency': currency, 'code': code, 'textid': textid, 'mu_id': MU_ID}
|
|
|
|
else:
|
|
print("skipping record, no valid Phone No. or ICCID")
|
|
|
|
continue
|
|
|
|
# this still works...
|
|
# create a dict for pairing by Phone No.
|
|
testcounter = 0
|
|
dirpath = "./output/"
|
|
mergedfile = [filename for filename in os.listdir(dirpath) if filename.startswith("merged_output_")]
|
|
with open(dirpath + mergedfile[0], 'r') as mergedfileread:
|
|
print("working with file: ",mergedfile[0])
|
|
readermerged =csv.DictReader(mergedfileread, delimiter=',')
|
|
for row in readermerged:
|
|
|
|
MSISDN = int(row['MSISDN'])
|
|
ICCID = row['ICCID']
|
|
IMSI = row['IMSI']
|
|
DATAPRICE = row['DATA-PRICE']
|
|
DATAAMOUNT = row['DATA-AMOUNT']
|
|
SMSPRICE= row['SMS-PRICE']
|
|
SMSCOUNT = row['SMS-COUNT']
|
|
OTHERPRICE = row['OTHER-PRICE']
|
|
SIMSTATUS = row['SIM-STATUS']
|
|
SN = row['SN']
|
|
SNDEC = row['SN-DEC']
|
|
LASTDATA = row['LAST-DATA']
|
|
OPERATOR = row['OPERATOR']
|
|
UNIT = row['UNIT']
|
|
print("UNIT: ", UNIT)
|
|
|
|
# Crawl through the pairing bis file
|
|
|
|
if MSISDN in bisbyphoneno:
|
|
amount = bisbyphoneno[MSISDN]['amount']
|
|
currency = bisbyphoneno[MSISDN]['currency']
|
|
code = bisbyphoneno[MSISDN]['code']
|
|
textid = bisbyphoneno[MSISDN]['textid']
|
|
mu_id = bisbyphoneno[MSISDN]['mu_id']
|
|
|
|
|
|
elif ICCID in bisbyiccid:
|
|
amount = bisbyiccid[ICCID]['amount']
|
|
currency = bisbyiccid[ICCID]['currency']
|
|
code = bisbyiccid[ICCID]['code']
|
|
textid = bisbyiccid[ICCID]['textid']
|
|
print("iccid: ", ICCID)
|
|
mu_id = bisbyiccid[ICCID]['mu_id']
|
|
|
|
|
|
else:
|
|
print("what is the issue here?: ",MSISDN, ICCID, IMSI)
|
|
print("just ignore this record")
|
|
amount = "N/A"
|
|
currency = "N/A"
|
|
code = "N/A"
|
|
textid = "N/A"
|
|
mu_id = "N/A"
|
|
testcounter += 1
|
|
print("testcounter: ", testcounter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
completepairing[MSISDN] = {'ICCID': ICCID, 'IMSI': IMSI, 'DATA-PRICE': DATAPRICE,
|
|
'DATA-AMOUNT': DATAAMOUNT, 'SMS-PRICE': SMSPRICE, 'SMS-COUNT': SMSCOUNT,
|
|
'OTHER-PRICE': OTHERPRICE, 'SIM-STATUS': SIMSTATUS, 'SN': SN,
|
|
'SN-DEC': SNDEC, 'UNIT': UNIT, 'LAST-DATA': LASTDATA, 'OPERATOR': OPERATOR,
|
|
'amount': amount, 'currency': currency, 'code': code, 'textid': textid, 'mu_id': mu_id}
|
|
# this still works...
|
|
|
|
|
|
|
|
filetoremove =pathlib.Path("./output/bis_merged_output.csv")
|
|
if filetoremove.exists():
|
|
os.remove("./output/bis_merged_output.csv")
|
|
|
|
with open(dirpath + 'bis_merged_output.csv', 'a', newline='', encoding="utf-8") as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(
|
|
["MSISDN", "ICCID", "IMSI", "DATA-PRICE", "DATA-AMOUNT", "SMS-PRICE", "SMS-COUNT", "OTHER-PRICE",
|
|
"SIM-STATUS", "SN", "SN-DEC", "UNIT", "LAST-DATA", "OPERATOR", "AMOUNT", "CURRENCY","AMOUNT-CZK", "CODE", "TEXTID", "SN-BIS"])
|
|
|
|
print("how many: ", len(completepairing.keys()))
|
|
rate = getCNBRates()
|
|
rate = str(rate).replace(",", "." )
|
|
|
|
|
|
for MSISDN in completepairing:
|
|
|
|
print("MSISDN: ", MSISDN)
|
|
|
|
IMSI = completepairing[MSISDN]['IMSI']
|
|
ICCID = completepairing[MSISDN]['ICCID']
|
|
DATAPRICE = completepairing[MSISDN]['DATA-PRICE']
|
|
DATAAMOUNT = completepairing[MSISDN]['DATA-AMOUNT']
|
|
SMSPRICE = completepairing[MSISDN]['SMS-PRICE']
|
|
SMSCOUNT = completepairing[MSISDN]['SMS-COUNT']
|
|
OTHERPRICE = completepairing[MSISDN]['OTHER-PRICE']
|
|
SIMSTATUS = completepairing[MSISDN]['SIM-STATUS']
|
|
SN = completepairing[MSISDN]['SN']
|
|
SNDEC = completepairing[MSISDN]['SN-DEC']
|
|
LASTDATA = completepairing[MSISDN]['LAST-DATA']
|
|
OPERATOR = completepairing[MSISDN]['OPERATOR']
|
|
amount = completepairing[MSISDN]['amount']
|
|
currency = completepairing[MSISDN]['currency']
|
|
code = completepairing[MSISDN]['code']
|
|
textid = completepairing[MSISDN]['textid']
|
|
UNIT = completepairing[MSISDN]['UNIT']
|
|
mu_id = completepairing[MSISDN]['mu_id']
|
|
# catch mu_id inconsistencies
|
|
if mu_id == "N/A":
|
|
mu_id = "N/A"
|
|
elif mu_id == "0":
|
|
mu_id = "N/A"
|
|
elif mu_id == "1":
|
|
mu_id = "N/A"
|
|
elif mu_id == "":
|
|
mu_id = "N/A"
|
|
|
|
|
|
print(amount)
|
|
if currency == "EUR":
|
|
amount = float(amount.replace(",", "." ))
|
|
amountczk = float(amount) * float(rate)
|
|
amountczk = round(amountczk, 2)
|
|
amountczk = str(amountczk).replace(".", "," )
|
|
amount = str(amount).replace(".", "," )
|
|
else:
|
|
amountczk = amount
|
|
|
|
writer.writerow([MSISDN, ICCID, IMSI, DATAPRICE, DATAAMOUNT, SMSPRICE, SMSCOUNT, OTHERPRICE, SIMSTATUS, SN, SNDEC, UNIT, LASTDATA, OPERATOR, amount, currency, amountczk, code, textid, mu_id])
|
|
print("Pairing BIS file with merged output file done")
|
|
|
|
def merge():
|
|
dirpath = "./output/"
|
|
tmgdspfile = [filename for filename in os.listdir(dirpath) if filename.startswith("output_TMGDSP_")]
|
|
tmgdspfile = tmgdspfile[0]
|
|
|
|
vfgdspfile = [filename for filename in os.listdir(dirpath) if filename.startswith("output_VFGDSP_")]
|
|
vfgdspfile = vfgdspfile[0]
|
|
|
|
tmczfile = [filename for filename in os.listdir(dirpath) if filename.startswith("output_TMCZ_")]
|
|
tmczfile = tmczfile[0]
|
|
|
|
vfczfile = [filename for filename in os.listdir(dirpath) if filename.startswith("output_VFCZ_")]
|
|
vfczfile = vfczfile[0]
|
|
|
|
FILE = [filename for filename in os.listdir(dirpath) if filename.startswith("VFGDSP_data_")]
|
|
FILE2 = [filename for filename in os.listdir(dirpath) if filename.startswith("Standard_Pairing_File")]
|
|
FILE3 = [filename for filename in os.listdir(dirpath) if filename.startswith("VFGDSP_sms_")]
|
|
|
|
|
|
|
|
ext_date_from_filaname = tmczfile.split('_')[-1]
|
|
# Help dicts
|
|
# tmcz_convertids
|
|
convert_tmcz = {}
|
|
|
|
|
|
with open('./help_files/TMCZ_IMSI.csv', 'r') as file:
|
|
reader =csv.DictReader(file, delimiter=';')
|
|
for row in reader:
|
|
print(row)
|
|
MSISDN = int(row['MSISDN'])
|
|
MSISDN = int(str(420)+str(MSISDN))
|
|
print(row['ICCID'])
|
|
print(row['IMSI'])
|
|
convert_tmcz[MSISDN] = {'iccid': row['ICCID'],'imsi': row['IMSI']}
|
|
print(MSISDN)
|
|
|
|
|
|
# vfcz_convertids
|
|
convert_vfcz = {}
|
|
|
|
with open('./help_files/VFCZ_IMSI.csv', 'r') as file:
|
|
reader =csv.DictReader(file, delimiter=';')
|
|
for row in reader:
|
|
print(row)
|
|
MSISDN = int(row['MSISDN'])
|
|
ICCID = int(row['ICCID'])
|
|
|
|
convert_vfcz[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}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("created dict to translate sns")
|
|
|
|
with open(dirpath+tmczfile, newline='', encoding="utf-8") as csvfile:
|
|
reader = csv.DictReader(csvfile, delimiter=',')
|
|
#next(reader)
|
|
print("got into reader func")
|
|
with open('./output/merged_output_'+ext_date_from_filaname, 'w', newline='', encoding="utf-8") as f:
|
|
writer = csv.writer(f)
|
|
|
|
writer.writerow(
|
|
["MSISDN", "ICCID", "IMSI", "DATA-PRICE", "DATA-AMOUNT", "SMS-PRICE", "SMS-COUNT", "OTHER-PRICE", "SIM-STATUS", "SN", "SN-DEC","UNIT", "LAST-DATA","OPERATOR"])
|
|
|
|
for row in reader:
|
|
#if istmczenabled == 0:
|
|
#print("tmcz disabled")
|
|
#break
|
|
|
|
print(row)
|
|
msisdn = int(row['MSISDN'])
|
|
print(type(msisdn))
|
|
print(msisdn)
|
|
|
|
if msisdn in convert_tmcz:
|
|
print("msisdn found in helper, we have iccid and imsi")
|
|
iccid = convert_tmcz[msisdn]['iccid']
|
|
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']
|
|
realsndate = serialnumberdict[int(imsitoconvert)]['date']
|
|
# strip realsndate to just date
|
|
realsndate = realsndatestrip(realsndate)
|
|
|
|
print(realsn)
|
|
|
|
else:
|
|
print("not found in helper, cannot convert to sn")
|
|
realsn = "unknown"
|
|
realsndate = "unknown"
|
|
|
|
else:
|
|
print("msisdn not found in helper, we dont have iccid and imsi")
|
|
iccid = "N/A"
|
|
imsi = "N/A"
|
|
realsn = "unknown"
|
|
realsndecadic = "unknown"
|
|
realsndate = "unknown"
|
|
|
|
dataprice = row['DATA-PRICE']
|
|
dataamount = row['DATA-AMOUNT']
|
|
smsprice = row['SMS-PRICE']
|
|
smscount = row['SMS-COUNT']
|
|
otherprice = row['OTHER-PRICE']
|
|
simstatus = row['SIM-STATUS']
|
|
operator = row['OPERATOR']
|
|
print("realsn: ",realsn)
|
|
|
|
if realsn.startswith('U'):
|
|
|
|
realsndecadic = realsn.split("-")
|
|
realsndecadic = realsndecadic[2]
|
|
print(realsndecadic)
|
|
realsndecadic = int(realsndecadic, 16)
|
|
|
|
else:
|
|
realsndecadic = realsn
|
|
if realsn != "unknown":
|
|
|
|
unit = realsn[ 0 : 4 ]
|
|
else:
|
|
unit = "unknown"
|
|
|
|
writer.writerow([msisdn, iccid, imsi, convertChars(dataprice), convertChars(dataamount), convertChars(smsprice), convertChars(smscount), convertChars(otherprice), simstatus, realsn, realsndecadic, unit, realsndate,operator])
|
|
print("Merged")
|
|
|
|
with open(dirpath+vfczfile, newline='', encoding="utf-8") as csvfile:
|
|
reader = csv.DictReader(csvfile, delimiter=',')
|
|
#next(reader)
|
|
print("got into reader func")
|
|
with open(dirpath+'merged_output_'+ext_date_from_filaname, 'a', newline='', encoding="utf-8") as f:
|
|
writer = csv.writer(f)
|
|
for row in reader:
|
|
|
|
msisdn = int(row['MSISDN'])
|
|
|
|
|
|
if msisdn in convert_vfcz:
|
|
print("msisdn found in helper, we have iccid and imsi")
|
|
iccid = convert_vfcz[msisdn]['iccid']
|
|
imsi = convert_vfcz[msisdn]['imsi']
|
|
print(imsi)
|
|
else:
|
|
print("Could not find in helper")
|
|
|
|
imsitoconvert = int(imsi)
|
|
print("imsi: ", imsi)
|
|
if imsitoconvert in serialnumberdict:
|
|
print("found in snhelper, can convert to sn")
|
|
realsn = serialnumberdict[int(imsi)]['sn']
|
|
realsndate = serialnumberdict[int(imsi)]['date']
|
|
# strip realsndate to just date
|
|
realsndate = realsndatestrip(realsndate)
|
|
print(realsn)
|
|
|
|
|
|
else:
|
|
print("msisdn not found in helper, we dont have sn")
|
|
realsn = "unknown"
|
|
realsndate = "unknown"
|
|
|
|
if realsn.startswith('U'):
|
|
|
|
realsndecadic = realsn.split("-")
|
|
realsndecadic = realsndecadic[2]
|
|
print(realsndecadic)
|
|
realsndecadic = int(realsndecadic, 16)
|
|
|
|
else:
|
|
realsndecadic = realsn
|
|
|
|
if realsn != "unknown":
|
|
|
|
unit = realsn[ 0 : 4 ]
|
|
else:
|
|
unit = "unknown"
|
|
|
|
dataprice = row['DATA-PRICE']
|
|
dataamount = row['DATA-AMOUNT']
|
|
smsprice = row['SMS-PRICE']
|
|
smscount = row['SMS-COUNT']
|
|
otherprice = row['OTHER-PRICE']
|
|
simstatus = row['SIM-STATUS']
|
|
operator = row['OPERATOR']
|
|
writer.writerow([msisdn, iccid, imsi, convertChars(dataprice), convertChars(dataamount), convertChars(smsprice), convertChars(smscount), convertChars(otherprice), simstatus, realsn, realsndecadic, unit, realsndate, operator])
|
|
|
|
|
|
with open(dirpath+vfgdspfile, newline='', encoding="utf-8") as csvfile:
|
|
reader = csv.DictReader(csvfile, delimiter=',')
|
|
#next(reader)
|
|
print("got into reader func")
|
|
with open(dirpath+'merged_output_'+ext_date_from_filaname, 'a', newline='', encoding="utf-8") as f:
|
|
writer = csv.writer(f)
|
|
for row in reader:
|
|
print(row)
|
|
msisdn = int(row['MSISDN'])
|
|
iccid = int(row['ICCID'])
|
|
imsi = int(row['IMSI'])
|
|
|
|
# grab sn from helper
|
|
|
|
|
|
if imsi in serialnumberdict:
|
|
print("found in snhelper, can convert to sn")
|
|
realsn = serialnumberdict[int(imsi)]['sn']
|
|
realsndate = serialnumberdict[int(imsi)]['date']
|
|
# strip realsndate to just date
|
|
realsndate = realsndatestrip(realsndate)
|
|
print(realsn)
|
|
|
|
|
|
else:
|
|
print("msisdn not found in helper, we dont have sn")
|
|
realsn = "unknown"
|
|
realsndate = "unknown"
|
|
|
|
if realsn.startswith('U'):
|
|
|
|
realsndecadic = realsn.split("-")
|
|
realsndecadic = realsndecadic[2]
|
|
print(realsndecadic)
|
|
realsndecadic = int(realsndecadic, 16)
|
|
|
|
else:
|
|
realsndecadic = realsn
|
|
|
|
if realsn != "unknown":
|
|
|
|
unit = realsn[ 0 : 4 ]
|
|
else:
|
|
unit = "unknown"
|
|
|
|
|
|
dataprice = row['DATA-PRICE']
|
|
dataamount = row['DATA-AMOUNT']
|
|
smsprice = row['SMS-PRICE']
|
|
smscount = row['SMS-COUNT']
|
|
otherprice = row['OTHER-PRICE']
|
|
simstatus = row['SIM-STATUS']
|
|
operator = row['OPERATOR']
|
|
writer.writerow([msisdn, iccid, imsi, convertChars(dataprice), convertChars(dataamount), convertChars(smsprice), convertChars(smscount), convertChars(otherprice), simstatus, realsn, realsndecadic, unit, realsndate, operator])
|
|
|
|
with open(dirpath+tmgdspfile, newline='', encoding="utf-8") as csvfile:
|
|
reader = csv.DictReader(csvfile, delimiter=',')
|
|
#next(reader)
|
|
print("got into reader func")
|
|
with open(dirpath+'merged_output_'+ext_date_from_filaname, 'a', newline='', encoding="utf-8") as f:
|
|
writer = csv.writer(f)
|
|
for row in reader:
|
|
print(row)
|
|
msisdn = int(row['MSISDN'])
|
|
iccid = int(row['ICCID'])
|
|
imsi = int(row['IMSI'])
|
|
# grab sn from helper
|
|
|
|
|
|
if imsi in serialnumberdict:
|
|
print("found in snhelper, can convert to sn")
|
|
realsn = serialnumberdict[int(imsi)]['sn']
|
|
realsndate = serialnumberdict[int(imsi)]['date']
|
|
# strip realsndate to just date
|
|
realsndate = realsndatestrip(realsndate)
|
|
|
|
|
|
else:
|
|
print("msisdn not found in helper, we dont have sn")
|
|
realsn = "unknown"
|
|
realsndate = "unknown"
|
|
|
|
if realsn.startswith('U'):
|
|
|
|
realsndecadic = realsn.split("-")
|
|
realsndecadic = realsndecadic[2]
|
|
print(realsndecadic)
|
|
realsndecadic = int(realsndecadic, 16)
|
|
|
|
else:
|
|
realsndecadic = realsn
|
|
|
|
if realsn != "unknown":
|
|
|
|
unit = realsn[ 0 : 4 ]
|
|
else:
|
|
unit = "unknown"
|
|
|
|
|
|
dataprice = row['DATA-PRICE']
|
|
dataamount = row['DATA-AMOUNT']
|
|
smsprice = row['SMS-PRICE']
|
|
smscount = row['SMS-COUNT']
|
|
otherprice = row['OTHER-PRICE']
|
|
simstatus = row['SIM-STATUS']
|
|
operator = row['OPERATOR']
|
|
print("before write: ",realsndate)
|
|
writer.writerow([msisdn, iccid, imsi, convertChars(dataprice), convertChars(dataamount), convertChars(smsprice), convertChars(smscount), convertChars(otherprice), simstatus,realsn ,realsndecadic, unit, realsndate, operator])
|
|
|
|
print("succesfuly merged")
|
|
|
|
|
|
|
|
def checkFiles():
|
|
print("button pressed")
|
|
dirpath = "./input/"
|
|
text = "testbutton"
|
|
FILE = [filename for filename in os.listdir(dirpath) if filename.startswith("TMGDSP_")]
|
|
FILE2 = [filename for filename in os.listdir(dirpath) if filename.startswith("VFGDSP_data_")]
|
|
FILE3 = [filename for filename in os.listdir(dirpath) if filename.startswith("Standard_Pairing_File")]
|
|
FILE4 = [filename for filename in os.listdir(dirpath) if filename.startswith("VFGDSP_sms_")]
|
|
FILE5 = [filename for filename in os.listdir(dirpath) if filename.startswith("TMCZ_")]
|
|
FILE6 = [filename for filename in os.listdir(dirpath) if filename.startswith("VFCZ_")]
|
|
FILE7 = [filename for filename in os.listdir("./help_files") if filename.startswith("VFCZ_IMSI")]
|
|
FILE8 = [filename for filename in os.listdir("./help_files") if filename.startswith("TMCZ_IMSI")]
|
|
FILE9 = [filename for filename in os.listdir("./help_files") if filename.startswith("config_parser")]
|
|
FILE10 = [filename for filename in os.listdir("./help_files") if filename.startswith("bis")]
|
|
|
|
|
|
b2['state'] = "active"
|
|
|
|
#TMGDSP
|
|
if FILE:
|
|
FILE = FILE[0]
|
|
file1area['text'] = FILE
|
|
file1area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file1area['text'] = "TMGDSP_ file not found"
|
|
file1area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
#VFGDSP
|
|
if FILE2:
|
|
FILE2 = FILE2[0]
|
|
file2area['text'] = FILE2
|
|
file2area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file2area['text'] = "VFGDSP_data file not found"
|
|
file2area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
if FILE3:
|
|
FILE3 = FILE3[0]
|
|
file3area['text'] = FILE3
|
|
file3area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file3area['text'] = "Standard_Pairing_File file not found"
|
|
file3area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
if FILE4:
|
|
FILE4 = FILE4[0]
|
|
file4area['text'] = FILE4
|
|
file4area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file4area['text'] = "VFGDSP_sms file not found"
|
|
file4area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
#TMCZ
|
|
if FILE5:
|
|
FILE5 = FILE5[0]
|
|
file5area['text'] = FILE5
|
|
file5area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file5area['text'] = "TMCZ file not found"
|
|
file5area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
#VFCZ
|
|
if FILE6:
|
|
FILE6 = FILE6[0]
|
|
file6area['text'] = FILE6
|
|
file6area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file6area['text'] = "VFCZ file not found"
|
|
file6area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
#VFCZ_IMSI
|
|
if FILE7:
|
|
FILE7 = FILE7[0]
|
|
modTimesinceEpoc = os.path.getmtime("./help_files/" + FILE7)
|
|
modificationTime = time.strftime('%Y-%m-%d', time.localtime(modTimesinceEpoc))
|
|
print("Last Modified Time : ", modificationTime)
|
|
file7area['text'] = FILE7 + " - " + modificationTime
|
|
file7area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file7area['text'] = "VFCZ_IMSI file not found"
|
|
file7area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
#TMCZ_IMSI
|
|
if FILE8:
|
|
FILE8 = FILE8[0]
|
|
modTimesinceEpoc = os.path.getmtime("./help_files/" + FILE8)
|
|
modificationTime = time.strftime('%Y-%m-%d', time.localtime(modTimesinceEpoc))
|
|
print("Last Modified Time : ", modificationTime)
|
|
file8area['text'] = FILE8 + " - " + modificationTime
|
|
file8area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file8area['text'] = "TMCZ_IMSI file not found"
|
|
file8area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
#config_parser
|
|
if FILE9:
|
|
FILE9 = FILE9[0]
|
|
|
|
modTimesinceEpoc = os.path.getmtime("./help_files/" + FILE9)
|
|
modificationTime = time.strftime('%Y-%m-%d', time.localtime(modTimesinceEpoc))
|
|
print("Last Modified Time : ", modificationTime)
|
|
|
|
file9area['text'] = FILE9 + " - " + modificationTime
|
|
file9area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file9area['text'] = "config_parser file not found"
|
|
file9area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
if FILE10:
|
|
FILE10 = FILE10[0]
|
|
|
|
modTimesinceEpoc = os.path.getmtime("./help_files/" + FILE10)
|
|
modificationTime = time.strftime('%Y-%m-%d', time.localtime(modTimesinceEpoc))
|
|
print("Last Modified Time : ", modificationTime)
|
|
|
|
file10area['text'] = FILE10 + " - " + modificationTime
|
|
file10area['bg'] = "#32CD32"
|
|
print("succ")
|
|
else:
|
|
print("no file found")
|
|
file10area['text'] = "BIS file not found"
|
|
file10area['bg'] = "#FF0000"
|
|
b2['state'] = "disable"
|
|
|
|
def help():
|
|
#filewin = Toplevel(root)
|
|
#button = Button(filewin, text="Do nothing button")
|
|
#button.pack()
|
|
print("")
|
|
messagebox.showinfo("showinfo", "Ferengi v "+ver+" by Jakub and Manik")
|
|
|
|
def addSerialNumbers():
|
|
|
|
|
|
messagebox.showinfo("showinfo", "Ferengi v 0.1 by Jakub")
|
|
|
|
|
|
def obtainIdFile():
|
|
|
|
print("Downloading config_parser file")
|
|
urllib.request.urlretrieve("http://certificates.princip.cz/ferengi/config_parser.csv", "./help_files/config_parser.csv")
|
|
print("Done")
|
|
|
|
def runBilling():
|
|
ret = sp.call(["python", "tmgdsp.py"])
|
|
if ret != 0:
|
|
raw_input()
|
|
|
|
ret = sp.call(["python", "vfgdsp_final.py"])
|
|
if ret != 0:
|
|
raw_input()
|
|
|
|
ret = sp.call(["python", "ucetnictvi_tm.py"])
|
|
if ret != 0:
|
|
raw_input()
|
|
|
|
ret = sp.call(["python", "ucetnictvi_vfcz.py"])
|
|
if ret != 0:
|
|
raw_input()
|
|
|
|
print("Billing done")
|
|
|
|
|
|
root = tk.Tk()
|
|
root.geometry("900x500")
|
|
root.title("Ferengi")
|
|
root.config(cursor='')
|
|
|
|
|
|
#root.rowconfigure(1, minsize=1, weight=10) # Here
|
|
|
|
|
|
|
|
|
|
|
|
#root.columnconfigure(1, minsize=1) # Here
|
|
#root.columnconfigure(0, minsize=1) # Here
|
|
|
|
|
|
tmgdsptext = "TMGDSP_ file not found"
|
|
|
|
vfgdsp1text = "VFGDSP_data file not found"
|
|
vfgdsp2text = "Standard_Pairing_File file not found"
|
|
vfgdsp3text = "VFGDSP_sms_ file not found"
|
|
|
|
tmcztext = "TMCZ_ file not found"
|
|
|
|
vfcztext = "VFCZ_ file not found"
|
|
|
|
helptext = "VFCZ_IMSI.csv file not found"
|
|
|
|
help2text = "TMCZ_IMSI.csv file not found"
|
|
|
|
help3text = "config_parser.csv file not found"
|
|
|
|
help4text = "bis file not found"
|
|
|
|
# TMGDSP
|
|
tmgdpssection = tk.Label( root, text="TMGDSP",borderwidth=0, relief="groove",width=60, anchor='w')
|
|
file1area = tk.Label( root, text=tmgdsptext,borderwidth=2, relief="groove",width=60)
|
|
|
|
# VFGDSP
|
|
vfgdsppssection = tk.Label( root, text="VFGDSP",borderwidth=0, relief="groove",width=60, anchor='w')
|
|
file2area = tk.Label( root, text=vfgdsp1text,borderwidth=2, relief="groove",width=60)
|
|
file3area = tk.Label( root, text=vfgdsp2text,borderwidth=2, relief="groove",width=60)
|
|
file4area = tk.Label( root, text=vfgdsp3text,borderwidth=2, relief="groove",width=60)
|
|
|
|
# TMCZ
|
|
tmczsection = tk.Label( root, text="TMCZ",borderwidth=0, relief="groove",width=60, anchor='w')
|
|
file5area = tk.Label( root, text=tmcztext,borderwidth=2, relief="groove",width=60)
|
|
|
|
# VFCZ
|
|
vfczsection = tk.Label( root, text="VFCZ",borderwidth=0, relief="groove",width=60, anchor='w')
|
|
file6area = tk.Label( root, text=vfcztext,borderwidth=2, relief="groove",width=60)
|
|
|
|
# help_files
|
|
helpsection = tk.Label( root, text="HELP FILES",borderwidth=0, relief="groove",width=60, anchor='w')
|
|
file7area = tk.Label( root, text=helptext,borderwidth=2, relief="groove",width=60)
|
|
|
|
file8area = tk.Label( root, text=help2text,borderwidth=2, relief="groove",width=60)
|
|
|
|
file9area = tk.Label( root, text=help3text,borderwidth=2, relief="groove",width=60)
|
|
|
|
file10area = tk.Label( root, text=help4text,borderwidth=2, relief="groove",width=60)
|
|
|
|
|
|
|
|
T = tk.Text(root, height=20, width=200)
|
|
|
|
# Create button for next text.button
|
|
b1 = tk.Button(root, text="Retest files", command=lambda: checkFiles(), width=20)
|
|
# Create an Exit button.
|
|
b2 = tk.Button(root, text="Run billing",
|
|
command=lambda: runBilling(), state="disable", width=20)
|
|
|
|
b3 = tk.Button(root, text="Merge",
|
|
command=lambda: merge(), width=20)
|
|
|
|
b4 = tk.Button(root, text="Download pairing file",
|
|
command=lambda: obtainIdFile(), width=20)
|
|
|
|
pairbis = tk.Button(root, text="Pair BIS data",
|
|
command=lambda: pairBis(), width=20)
|
|
ToolTip(pairbis,'This merges the Ferengi merged file with BIS merged file', delay=2.0)
|
|
|
|
ToolTip(b3,'Merges all output files together after billing', delay=2.0)
|
|
ToolTip(b2,'This uses all modules for operators to obtain 4 output files', delay=2.0)
|
|
ToolTip(b1,'Checks all needed files', delay=2.0)
|
|
ToolTip(b4,'Downloads latest pairing.csv help file', delay=2.0)
|
|
|
|
buttonnewwindow = tk.Button(root,
|
|
text ="Show results",
|
|
command = buttonnewwindow, width=20)
|
|
ToolTip(buttonnewwindow,'Just a simple overview', delay=2.0)
|
|
# Everything to grid
|
|
|
|
tmgdpssection.place(x=10, y=10)
|
|
file1area.place(x=10, y=30)
|
|
vfgdsppssection.place(x=10, y=55)
|
|
file2area.place(x=10, y=75)
|
|
file3area.place(x=10, y=95)
|
|
file4area.place(x=10, y=115)
|
|
|
|
tmczsection.place(x=10, y=140)
|
|
file5area.place(x=10, y=160)
|
|
vfczsection.place(x=10, y=185)
|
|
file6area.place(x=10, y=205)
|
|
helpsection.place(x=10, y=230)
|
|
file7area.place(x=10, y=250)
|
|
file8area.place(x=10, y=270)
|
|
file9area.place(x=10, y=290)
|
|
file10area.place(x=10, y=310)
|
|
|
|
menubar = tk.Menu(root)
|
|
filemenu = tk.Menu(menubar, tearoff=0)
|
|
|
|
|
|
filemenu.add_command(label="Exit", command=root.quit)
|
|
filemenu.add_command(label="Config", command=openConfig)
|
|
menubar.add_cascade(label="File", menu=filemenu)
|
|
editmenu = tk.Menu(menubar, tearoff=0)
|
|
|
|
|
|
|
|
helpmenu = tk.Menu(menubar, tearoff=0)
|
|
|
|
helpmenu.add_command(label="About", command=help)
|
|
helpmenu.add_command(label="Update", command=updateapp)
|
|
menubar.add_cascade(label="Help", menu=helpmenu)
|
|
|
|
|
|
root.config(menu=menubar)
|
|
|
|
|
|
|
|
b1.place(x=450, y=60)
|
|
b2.place(x=450, y=120)
|
|
b3.place(x=450, y=150)
|
|
b4.place(x=450, y=90)
|
|
buttonnewwindow.place(x=450, y=210)
|
|
pairbis.place(x=450, y=180)
|
|
|
|
versionlabel = tk.Label(root,text=ver)
|
|
|
|
versionlabel.place(relx=1.0, rely=1.0,anchor ='se')
|
|
|
|
"""
|
|
height = 5
|
|
width = 5
|
|
for i in range(height): #Rows
|
|
for j in range(width): #Columns
|
|
b = tk.Entry(root, text="")
|
|
b.grid(row=i, column=j)
|
|
"""
|
|
|
|
|
|
|
|
|
|
root.after(0, checkFiles)
|
|
tk.mainloop() |