Config added, output view added

This commit is contained in:
2022-09-11 18:24:30 +02:00
parent d8d6613249
commit 95942285cc

315
main.py
View File

@@ -8,6 +8,10 @@ import pandas as pd
import glob
import urllib.request
import csv
from datetime import datetime
import time
import configparser
from pandastable import Table
outvar = {}
@@ -22,6 +26,62 @@ def convertChars(val):
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/"
@@ -37,6 +97,13 @@ def merge():
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 = {}
@@ -49,6 +116,18 @@ def merge():
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 = {}
@@ -94,10 +173,16 @@ def merge():
reader = csv.DictReader(csvfile, delimiter=',')
#next(reader)
print("got into reader func")
with open('./output/output_testmerge.csv', 'w', newline='', encoding="utf-8") as f:
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))
@@ -115,18 +200,24 @@ def merge():
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']
@@ -136,18 +227,65 @@ def merge():
simstatus = row['SIM-STATUS']
operator = row['OPERATOR']
print("realsn: ",realsn)
writer.writerow([msisdn, iccid, imsi, convertChars(dataprice), convertChars(dataamount), convertChars(smsprice), convertChars(smscount), convertChars(otherprice), simstatus, realsn, operator])
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_testmerge.csv', 'a', newline='', encoding="utf-8") as f:
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'])
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']
@@ -155,14 +293,14 @@ def merge():
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, "unknown",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_testmerge.csv', 'a', newline='', encoding="utf-8") as f:
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)
@@ -176,12 +314,26 @@ def merge():
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']
@@ -190,13 +342,13 @@ def merge():
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, 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_testmerge.csv', 'a', newline='', encoding="utf-8") as f:
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)
@@ -209,12 +361,25 @@ def merge():
if imsi in serialnumberdict:
print("found in snhelper, can convert to sn")
realsn = serialnumberdict[int(imsi)]['sn']
print(realsn)
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']
@@ -223,7 +388,8 @@ def merge():
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 ,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")
@@ -239,6 +405,10 @@ def checkFiles():
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"
@@ -312,12 +482,60 @@ def checkFiles():
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.1 by Jakub")
messagebox.showinfo("showinfo", "Ferengi v 0.2.4 by Jakub and Manik")
def addSerialNumbers():
@@ -328,7 +546,7 @@ def addSerialNumbers():
def obtainIdFile():
print("Downloading config_parser file")
urllib.request.urlretrieve("http://certificates.princip.cz/config_parser.csv", "./help_files/config_parser.csv")
urllib.request.urlretrieve("http://certificates.princip.cz/ferengi/config_parser.csv", "./help_files/config_parser.csv")
print("Done")
def runBilling():
@@ -377,7 +595,11 @@ 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')
@@ -397,39 +619,57 @@ file5area = tk.Label( root, text=tmcztext,borderwidth=2, relief="groove",width=6
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())
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")
command=lambda: runBilling(), state="disable", width=20)
b3 = tk.Button(root, text="Merge",
command=lambda: merge())
command=lambda: merge(), width=20)
b4 = tk.Button(root, text="Download pairing file",
command=lambda: obtainIdFile())
command=lambda: obtainIdFile(), width=20)
buttonnewwindow = tk.Button(root,
text ="Show results",
command = buttonnewwindow, width=20)
# Everything to grid
tmgdpssection.grid(row=1, column=1)
file1area.grid(row=2, column=1)
vfgdsppssection.grid(row=3, column=1)
file2area.grid(row=4, column=1)
file3area.grid(row=5, column=1)
file4area.grid(row=6, column=1)
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.grid(row=7, column=1)
file5area.grid(row=8, column=1)
vfczsection.grid(row=9, column=1)
file6area.grid(row=10, column=1)
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)
@@ -444,10 +684,23 @@ root.config(menu=menubar)
b1.grid(row=4, column=2)
b2.grid(row=5, column=2)
b3.grid(row=6, column=2)
b4.grid(row=7, column=2)
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()