From 9a71044bb573fa9c1ebb09917e1bf93adead0848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1=C4=8Dek?= Date: Tue, 2 Aug 2022 00:39:15 +0200 Subject: [PATCH] TEST --- main.py | 363 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 363 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..e58323c --- /dev/null +++ b/main.py @@ -0,0 +1,363 @@ +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 + +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 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] + + 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']} + + + + + + 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(dirpath+'output_testmerge.csv', 'w', newline='', encoding="utf-8") as f: + writer = csv.writer(f) + + for row in reader: + 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'] + + + else: + print("msisdn not found in helper, we dont have iccid and imsi") + iccid = "N/A" + imsi = "N/A" + + 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, dataprice, dataamount, smsprice, smscount, otherprice, simstatus, 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: + writer = csv.writer(f) + for row in reader: + print(row) + msisdn = int(row['MSISDN']) + 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, dataprice, dataamount, smsprice, smscount, otherprice, simstatus, 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: + writer = csv.writer(f) + for row in reader: + print(row) + msisdn = int(row['MSISDN']) + 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, dataprice, dataamount, smsprice, smscount, otherprice, simstatus, 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: + writer = csv.writer(f) + for row in reader: + print(row) + msisdn = int(row['MSISDN']) + 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, dataprice, dataamount, smsprice, smscount, otherprice, simstatus, operator]) + + + +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_")] + + 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" + +def help(): + #filewin = Toplevel(root) + #button = Button(filewin, text="Do nothing button") + #button.pack() + print("") + messagebox.showinfo("showinfo", "Ferengi v 0.1 by Jakub") + +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/config_parser.csv", "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" + + + +# 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) + +T = tk.Text(root, height=20, width=200) + +# Create button for next text.button +b1 = tk.Button(root, text="Retest files", command=lambda: checkFiles()) +# Create an Exit button. +b2 = tk.Button(root, text="Run billing", + command=lambda: runBilling(), state="disable") + +b3 = tk.Button(root, text="Merge", + command=lambda: merge()) + +b4 = tk.Button(root, text="Download pairing file", + command=lambda: obtainIdFile()) + +# 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) + +tmczsection.grid(row=7, column=1) +file5area.grid(row=8, column=1) +vfczsection.grid(row=9, column=1) +file6area.grid(row=10, column=1) + +menubar = tk.Menu(root) +filemenu = tk.Menu(menubar, tearoff=0) + + +filemenu.add_command(label="Exit", command=root.quit) +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.grid(row=4, column=2) +b2.grid(row=5, column=2) +b3.grid(row=6, column=2) +b4.grid(row=7, column=2) + +root.after(0, checkFiles) +tk.mainloop()