add: schedule for today and tomorrow; update: showing data

This commit is contained in:
mnjx
2023-04-14 20:14:18 +02:00
parent e2e970b7ff
commit 93fe4ff01c
5 changed files with 321 additions and 62 deletions
+34 -28
View File
@@ -2,16 +2,14 @@ from lib import networking as nw
from bs4 import BeautifulSoup
not_login = 0
F_not_anymore = 0
def fetch_locally() -> list:
global not_login, F_not_anymore
global not_login
if not_login == 1 and F_not_anymore == 0:
F_not_anymore = 1
if not_login == 1:
not_login = 0
print("Could not sign in (you may have entered invalid login credentials)")
print("Fetching locally\n")
#print("Could not sign in (you may have entered invalid login credentials)")
#print("Fetching grades locally\n")
grades = grades_from_file()
return grades
@@ -32,31 +30,38 @@ def get_avg(grades: list) -> str:
return avg
def get_grades(url: str):
html = nw.get_html_from(url)
try:
html = nw.get_html_from(url)
soup = BeautifulSoup(html.text, "lxml")
soup = BeautifulSoup(html.text, "lxml")
rows = soup.find("table", id="G_ctl00xmainxCCADynamicUWGrid").find_all("tr")
for i in range(3):
r = soup.find("table", id="G_ctl00xmainxCCADynamicUWGrid").find("tr")
r.decompose()
grades = []
for i in range(1, len(rows)):
if rows[i].find("td") is not None:
subject = rows[i].find("td").text
temp_dict = {}
temp_dict["SUBJECT"] = subject
cell = rows[i].find_all("span", class_="VHVysl")
temp = []
for j in range(len(cell)):
temp.append(cell[j].text)
temp_dict["GRADES"] = temp
rows = soup.find("table", id="G_ctl00xmainxCCADynamicUWGrid").find_all("tr")
for i in range(3):
r = soup.find("table", id="G_ctl00xmainxCCADynamicUWGrid").find("tr")
r.decompose()
grades = []
for i in range(1, len(rows)):
if rows[i].find("td") is not None:
subject = rows[i].find("td").text
temp_dict = {}
temp_dict["SUBJECT"] = subject
cell = rows[i].find_all("span", class_="VHVysl")
temp = []
for j in range(len(cell)):
temp.append(cell[j].text)
temp_dict["GRADES"] = temp
grades.append(temp_dict)
grades.append(temp_dict)
return grades
return grades
except AttributeError:
global not_login
not_login = 1
grades = fetch_locally()
return grades
def show_grades():
if nw.is_connected() == True:
@@ -73,6 +78,8 @@ def show_grades():
max_len_of_subject = len(i)
max_len_of_subject += 1
print("")
print("--------")
print(" Známky ")
print("--------\n")
@@ -92,7 +99,6 @@ def show_grades():
print(get_avg(grades[i]["GRADES"]), "|", end=" ")
print("".join([grades[i]["GRADES"][j]+" " for j in range(len(grades[i]["GRADES"]))]), end=" ")
print("")
print("")
def grades_to_file(grades=None): # !!! make sure the format of the grades list is saved correctly !!!
import csv