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 outvar = {} """ def merge(): interesting_files = glob.glob("./output/*.csv") df = pd.concat((pd.read_csv(f, header = 0) for f in interesting_files)) df.to_csv("./output/global_output.csv",index=False,index_label=None,columns=None) """ def convertChars(val): converted = val.replace(',', '') converted = converted.replace('.', ',') return converted def openConfig(): configwindow = tk.Toplevel(root) configwindow.title("Config") configwindow.geometry("320x150") #frame = tk.Frame(config) config = configparser.ConfigParser() config.read('config.conf') tmgdspen = config.get('modules', 'tmgdsp') vfgdspen = config.get('modules', 'vfgdsp') tmczen = config.get('modules', 'tmcz') vfczen = config.get('modules', 'vfcz') print(tmgdspen) print(vfgdspen) print(tmczen) print(vfczen) tmgdspen = tmgdspen.get() checktmgdsp = ttk.Checkbutton(configwindow, text="TMGDSP", variable=tmgdspen, onvalue = 1, offvalue = 0) checktmgdsp.place(x=10, y=10) checkvfgdsp = ttk.Checkbutton(configwindow, text="VFGDSP", variable=vfgdspen, onvalue = 1, offvalue = 0) checkvfgdsp.place(x=10, y=30) checktmcz = ttk.Checkbutton(configwindow, text="TMCZ", variable=tmczen, onvalue = 1, offvalue = 0) checktmcz.place(x=10, y=50) checkvfcz = ttk.Checkbutton(configwindow, text="VFCZ", variable=vfczen, onvalue = 1, offvalue = 0) checkvfcz.place(x=10, y=70) 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() table.importCSV('output/global_output.csv') 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 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: MSISDN = int(row['MSISDN']) print(row['ICCID']) print(row['IMSI']) convert_tmcz[MSISDN] = {'iccid': row['ICCID'],'imsi': row['IMSI']} # 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/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", "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 writer.writerow([msisdn, iccid, imsi, convertChars(dataprice), convertChars(dataamount), convertChars(smsprice), convertChars(smscount), convertChars(otherprice), simstatus, realsn, realsndecadic, 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+'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 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, 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+'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 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, 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+'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 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, 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")] 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(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" def help(): #filewin = Toplevel(root) #button = Button(filewin, text="Do nothing button") #button.pack() print("") messagebox.showinfo("showinfo", "Ferengi v 0.2.4 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() 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" # 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) 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) buttonnewwindow = tk.Button(root, text ="Show results", command = buttonnewwindow, width=20) # 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) 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) menubar.add_cascade(label="Help", menu=helpmenu) root.config(menu=menubar) b1.place(x=450, y=60) b2.place(x=450, y=90) b3.place(x=450, y=120) b4.place(x=450, y=150) buttonnewwindow.place(x=450, y=180) """ 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()