Skip to content

Commit

Permalink
changed the folder structure and made v4 an alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
pagega committed Dec 6, 2023
1 parent 05521f2 commit 945207e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 35 deletions.
Binary file added Executables/Viewer V4 alpha.exe
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 63 additions & 26 deletions Viewer V3.py → Quellcode/Viewer V3.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from typing import Any
import requests
from tabulate import tabulate
from tkinter import *
from datetime import datetime, timedelta
from tkinter import ttk
import customtkinter as ctk
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

class DATA:
@classmethod
def initialize(cls):
def initialize(cls, tage):

# Initialize data from WebUntis API
cls.days = DATA.mögliche_tage()
cls.days = DATA.mögliche_tage(tage)
cls.data = DATA.request_data(cls.days)
cls.clean_data = DATA.cleanup_data(cls.data, cls.days)

Expand All @@ -36,9 +38,7 @@ def get_data_from_WebUntis(days):
# Headers, cookies, and parameters for the WebUntis API request

for dates in days:

print(f"Proceeding date.......{dates}")


#Place cUrl command after:
cookies = {
'traceId': 'c6d915932d178a01b45014d09ed504ce9c790385',
Expand Down Expand Up @@ -120,6 +120,7 @@ def get_data_from_WebUntis(days):
headers=headers,
json=json_data,
)

data[dates] = response.json()

#cUrl should end here. your script-block should look nearly the same as the one here
Expand Down Expand Up @@ -148,7 +149,7 @@ def cleanup_data(data,days):


@staticmethod
def mögliche_tage():
def mögliche_tage(iterations):
# Function to get a list of possible dates for the GUI

# Function to skip Saturday and Sunday
Expand All @@ -164,9 +165,9 @@ def naechster_werktag(datum):

if heutiges_datum.weekday() != 5 and heutiges_datum.weekday() != 6:
naechste_tage.append(datetime.now().strftime('%Y%m%d'))
tage = 30
tage = iterations - 1
else:
tage = 31
tage = iterations


for _ in range(tage):
Expand Down Expand Up @@ -200,7 +201,7 @@ def umwandeln_datum(datum_integer):
# Create the GUI
class GUI:

def __init__(self, master):
def __init__(self, master_root):

self.date_color = '#0F0F0F'
self.odd_color = '#1E1E1E'
Expand All @@ -209,9 +210,13 @@ def __init__(self, master):
self.heading_color = '#FF7832'
self.class_menu_color = '#FF7832'

self.scrollbar_table = Scrollbar(master, orient=VERTICAL)
master.style = ttk.Style()
master.style.configure('My.Vertical.TScrollbar', background='black', troughcolor='black', activebackground='black')
self.master = ctk.CTkScrollableFrame(master_root,
orientation=VERTICAL,
fg_color='teal',
scrollbar_button_color='orange',
scrollbar_button_hover_color='darkorange',
corner_radius=10
)

# Initialize the GUI
self.keys = []
Expand All @@ -220,13 +225,13 @@ def __init__(self, master):
self.keys.append(key)

self.page_number = 1
self.master = master
self.master = self.master

self.selected_class = StringVar(master)
self.selected_class = StringVar(self.master)
self.selected_class.set('BG 13')
self.selected_class.trace_add('write', self.update_gui_data)

self.class_menu = OptionMenu(master, self.selected_class, *self.keys)
self.class_menu = OptionMenu(self.master, self.selected_class, *self.keys)
self.class_menu.configure(relief= 'raised', bg= self.class_menu_color, highlightthickness= 0.5, highlightbackground= 'black', foreground = 'white')
self.class_menu.grid(row=2, column=0, columnspan=3, padx= 500, sticky= 'we')

Expand All @@ -235,14 +240,12 @@ def __init__(self, master):
self.empty_label.grid(row=3, column=0, sticky= 'we')

# Create a table
self.table_view = ttk.Treeview(master, columns=(1, 2, 3, 4, 5), show='')
self.table_view.config(yscrollcommand=self.scrollbar_table.set)
self.table_view = ttk.Treeview(self.master, columns=(1, 2, 3, 4, 5), show='')
self.table_view.grid(row=4, column=0, columnspan=1)

self.scrollbar_table.config(command=self.table_view.yview)
self.scrollbar_table.grid(row=4, column=1, rowspan=1, sticky=NS)

'''scrollbar_table = Scrollbar(master, orient=VERTICAL,)
self.master.grid()
'''scrollbar_table = Scrollbar(self.master, orient=VERTICAL,)
scrollbar_table.config(command=self.table_view.yview, bg = 'black', activebackground= 'black')
scrollbar_table.grid(row=4, column=1, rowspan= 1, sticky= NS)'''

Expand Down Expand Up @@ -323,7 +326,8 @@ def update_table_view(self, *args):
self.table_view.insert("", "end", values=content, tags=('oddrow',))

index += 1


self.master.config()


def update_gui_data(self, *args):
Expand All @@ -334,15 +338,48 @@ def update_gui_data(self, *args):

self.update_table_view()


class Startup:

def __init__(self, master):

# Initialize the data after the GUI is set up
DATA.initialize()
self.master = master
self.welcome_label = Label(master, text= "Willkommen, gebe hier die Anzahl der Tage ein die geladen werden sollen :)", bg='#1E1E1E', foreground= 'white')
self.entry = Entry(master)
self.confirm_button = Button(master,text= "Bestätige hier", command=self.confirm_clicked, bg='#FF7832', foreground= 'white')

self.status_label = Label(master, text="Lade Daten, bitte Warten...", bg='#1E1E1E', foreground= 'white', justify= 'center')

self.welcome_label.grid(row=0, column=0, padx= 5, pady= 5)
self.entry.grid(row=1, column=0, sticky= 'we', padx= 5, pady= 5)
self.confirm_button.grid(row=2, column=0, sticky= 'we', padx= 5, pady= 5)

def confirm_clicked(self):
tage = int(self.entry.get())
self.welcome_label.destroy()
self.entry.destroy()
self.confirm_button.destroy()
self.status_label.pack()

# Schedule the initialize method after a short delay
root.after(100, self.initialize_data, tage)

def initialize_data(self, tage):
DATA.initialize(tage)
root.destroy()

def update_data(self, data):
self.status_label.config(self.master, text=data)


# Create the main Tkinter window
root = Tk()
root.configure(bg='#1E1E1E')
root.geometry("410x100")
first_gui = Startup(root)
root.mainloop()


# Create an instance of the GUI class
root = Tk()
root.configure(bg='#1E1E1E')
gui = GUI(root)
# Start the Tkinter event loop
root.mainloop()
34 changes: 25 additions & 9 deletions Viewer V4.py → Quellcode/Viewer V4.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@ def initialize(cls, tage):

# Initialize data from WebUntis API
cls.days = DATA.mögliche_tage(tage)
cls.data = DATA.request_data(cls.days)
cls.data = DATA.request_data(cls.days, tage)
cls.clean_data = DATA.cleanup_data(cls.data, cls.days)

@staticmethod
def request_data(days):
def request_data(days, tage):
retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
session = requests.Session()
session.mount('http://', HTTPAdapter(max_retries=retries))
session.mount('https://', HTTPAdapter(max_retries=retries))

try:
data = DATA.get_data_from_WebUntis(days)
data = DATA.get_data_from_WebUntis(days, tage)
return data
except requests.exceptions.RequestException as e:
print(f"Error: {e}")

@staticmethod
def get_data_from_WebUntis(days):
def get_data_from_WebUntis(days, anzahl_tage):
# Function to retrieve data from the WebUntis API

data = {}
# Headers, cookies, and parameters for the WebUntis API request

for dates in days:


datum = dates
gui.master.after(100, gui.update_data, f"Lade Daten für {datum}")
datum = f"{dates[6:8]}.{dates[4:6]}.{dates[:4]}" # dates in the format yyyymmdd and should be dd.mm.yyyy
first_gui.status_label.config(text=f"Lade Daten für den {datum}")
root.update()

first_gui.status_label.config(text="lol")
#Place cUrl command after:
cookies = {
'traceId': 'c6d915932d178a01b45014d09ed504ce9c790385',
Expand Down Expand Up @@ -126,6 +127,9 @@ def get_data_from_WebUntis(days):

data[dates] = response.json()

first_gui.pb['value'] += 100/anzahl_tage
root.update()

#cUrl should end here. your script-block should look nearly the same as the one here
return data

Expand Down Expand Up @@ -343,12 +347,23 @@ class Startup:

def __init__(self, master):

s = ttk.Style()
s.theme_use('clam')
s.configure("red.Horizontal.TProgressbar", background='#FF7832', troughcolor='black')

self.master = master
self.welcome_label = Label(master, text= "Willkommen, gebe hier die Anzahl der Tage ein die geladen werden sollen :)", bg='#1E1E1E', foreground= 'white')
self.entry = Entry(master)
self.confirm_button = Button(master,text= "Bestätige hier", command=self.confirm_clicked, bg='#FF7832', foreground= 'white')

self.status_label = Label(master, text="Lade Daten, bitte Warten...", bg='#1E1E1E', foreground= 'white', justify= 'center')
self.status_label = Label(master, text="Lade Daten, bitte Warten...", bg='#1E1E1E', foreground= 'white', justify= 'center')
self.pb = ttk.Progressbar(
root,
orient='horizontal',
mode='determinate',
length=280,
style= 'red.Horizontal.TProgressbar'
)

self.welcome_label.grid(row=0, column=0, padx= 5, pady= 5)
self.entry.grid(row=1, column=0, sticky= 'we', padx= 5, pady= 5)
Expand All @@ -360,6 +375,7 @@ def confirm_clicked(self):
self.entry.destroy()
self.confirm_button.destroy()
self.status_label.pack()
self.pb.pack()

# Schedule the initialize method after a short delay
root.after(100, self.initialize_data, tage)
Expand All @@ -375,7 +391,7 @@ def update_data(self, data):
root = Tk()
root.configure(bg='#1E1E1E')
root.geometry("410x100")
gui = Startup(root)
first_gui = Startup(root)
root.mainloop()


Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 945207e

Please sign in to comment.