From 054925ea03f810398f992dba6317410b024302b3 Mon Sep 17 00:00:00 2001 From: mrraclette Date: Mon, 16 Oct 2023 21:37:36 +0200 Subject: [PATCH] reader into gui --- datareader.py | 25 ---------------- main.py | 80 +++++++++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 66 deletions(-) delete mode 100644 datareader.py diff --git a/datareader.py b/datareader.py deleted file mode 100644 index 80c62c5..0000000 --- a/datareader.py +++ /dev/null @@ -1,25 +0,0 @@ -import requests, json, jaro, zipfile, os - -#Get the name from the web site parcourstup -r = requests.get("https://ressource.parcoursup.fr/data/files.xml") -name = r.content[102:135].decode() -print(f"https://ressource.parcoursup.fr/data/{name}.zip") - -# Download the dataset if it doesn't already exist -if not os.path.exists(name): - r = requests.get(f"https://ressource.parcoursup.fr/data/{name}.zip") - with open('data.zip', 'wb') as file: - file.write(r.content) - with zipfile.ZipFile('data.zip', 'r') as zip_ref: - zip_ref.extractall() - -# Load database -print("Loading database ...") -with open(name, "r") as file: - database = json.loads(file.read()) - -def get_formations(prompt: str): - indices = [max([(jaro.jaro_winkler_metric(actual_word, word), index) for word, index in database["lexique"]["index"].items()], key=lambda x: x[0])[1] for actual_word in prompt.split()] - return [f"{formation['nm']} - {list(formation['recS'].keys())[-1]}" for formation in database["formations"].values() if all([str(index) in formation["recW"] for index in indices])] - -print(get_formations(input("Votre projet > "))) \ No newline at end of file diff --git a/main.py b/main.py index e578dff..2178793 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,34 @@ from tkinter import * from tkinter import ttk from tkinter import messagebox +import requests, json, jaro, zipfile, os import tkinter as tk + +#Get the name from the web site parcourstup +r = requests.get("https://ressource.parcoursup.fr/data/files.xml") +name = r.content[102:135].decode() +print(f"https://ressource.parcoursup.fr/data/{name}.zip") + +# Download the dataset if it doesn't already exist +if not os.path.exists(name): + r = requests.get(f"https://ressource.parcoursup.fr/data/{name}.zip") + with open('data.zip', 'wb') as file: + file.write(r.content) + with zipfile.ZipFile('data.zip', 'r') as zip_ref: + zip_ref.extractall() + +# Load database +print("Loading database ...") +with open(name, "r") as file: + database = json.loads(file.read()) + +def get_formations(prompt: str): + indices = [max([(jaro.jaro_winkler_metric(actual_word, word), index) for word, index in database["lexique"]["index"].items()], key=lambda x: x[0])[1] for actual_word in prompt.split()] + return [f"{formation['nm']} - {list(formation['recS'].keys())[-1]}" for formation in database["formations"].values() if all([str(index) in formation["recW"] for index in indices])] + + #creation première fenetre window = Tk() def __init__(window): @@ -14,16 +39,9 @@ window.title("Choix EDS") window.geometry("1080x720") window.minsize(480, 360) window.maxsize(1920, 1080) -window.iconbitmap("GUI/bitmap.ico") +window.iconbitmap("assets/bitmap.ico") window.config() -Thm = "#aaaaaa" -def makeSomething1(): - Thm = "#aaaaaa" - print(Thm) -def makeSomething2(): - Thm = "#35363a" - print(Thm) #Listbox/scrollbar #création scrollbar scrollbar = ttk.Scrollbar(window) @@ -32,24 +50,14 @@ scrollbar.config(command=listbox.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) listbox.pack(fill=tk.BOTH, expand=True) + #CREATIONN DES FRAMES -#création d'une frame principale frame = ttk.Frame(listbox) - -#création d'une frame haute highframe = ttk.Frame(frame) - -#création d'une frame basse bottomframe = ttk.Frame(frame) -#création d'une frame gauche -leftframe = ttk.Frame(bottomframe) - -#création d'une frame droite -rightframe = ttk.Frame(bottomframe) #Création menu bar - menubar = Menu(window) window.config(menu=menubar) menuabout = Menu(menubar,tearoff=0) @@ -68,15 +76,12 @@ menuabout.add_command(label="En savoir plus...", command=msgabout) menunon.add_command(label="Ne pas toucher", command=msgabout2) - - - #AJOUT ET AFFICHAGE DES ELEMENTS #affichagge image can = Canvas(highframe, width = 200 , height = 100) can.pack() -Objet_Image = PhotoImage(file='GUI/Logo.png') +Objet_Image = PhotoImage(file='assets/Logo.png') Image_Affichee = can.create_image(0,0, image = Objet_Image, anchor='nw') #ajouter le titre label_title = ttk.Label(highframe, text="Aide au choix des spécialités", font=("Arial", 31)) @@ -85,39 +90,36 @@ label_title.pack(side=tk.TOP, pady=8) #ajouter la description label_subtitle = ttk.Label(highframe, text="Cette application est une assistance pour le choix des EDS et du parcours post BAC", font=("Arial", 16)) -#afficher la description label_subtitle.pack() #ajouter un champ de texte -int_prompt = ttk.Entry(leftframe, font=("Arial", 16)) +int_prompt = ttk.Entry(highframe, font=("Arial", 16)) #afficher le champ de texte -int_prompt.pack(expand=YES, fill=X, pady=25) +int_prompt.pack(side=LEFT, expand=YES, fill=X, pady=25) #ajouter un bouton #définir fonction du bouton -def getEntry(*_): - prompt = int_prompt.get() - print(prompt) +prompt = "" -click_btn= PhotoImage(file='GUI/Search_button.png') +def getEntry(*_): + prompt = int_prompt.get() + print(get_formations(prompt)) + +click_btn= PhotoImage(file='assets/Search_button.png') #Let us create a label for button event img_label= Label(image=click_btn) #Let us create a dummy button and pass the image -button= Button(rightframe, image=click_btn,command= getEntry, +button= Button(highframe, image=click_btn,command= getEntry, borderwidth=0) -button.pack(pady=30) - - - +button.pack(side=RIGHT, pady=30) #creer bouton #assingner boutton entrée window.bind("", getEntry) - #AFFICHAGE DES FRAMES #affichage frame haute highframe.pack(side=TOP) @@ -125,11 +127,6 @@ highframe.pack(side=TOP) #affichage frame basse bottomframe.pack(side=BOTTOM) -#affichage frame droite -rightframe.pack(side=RIGHT, padx=10) - -#affichage frame gauche -leftframe.pack(side=LEFT, padx=10) #afficher la frame frame.pack(fill=tk.BOTH) @@ -139,5 +136,6 @@ frame.pack(fill=tk.BOTH) + #affichage dans la boucle main window.mainloop() \ No newline at end of file