fix: general bugfixes, display errors

This commit is contained in:
mnjx
2023-04-23 20:05:21 +02:00
parent 93fe4ff01c
commit d9c1b6fc92
6 changed files with 532 additions and 453 deletions
+1
View File
@@ -0,0 +1 @@
1
1
+1
View File
@@ -0,0 +1 @@
1
1
+1
View File
@@ -0,0 +1 @@
1
1
+47 -10
View File
@@ -1,5 +1,3 @@
# fetch the schedule for today and tomorrow from the landing page of ŠOL
from lib import networking as nw from lib import networking as nw
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@@ -11,7 +9,7 @@ def fetch_locally() -> list:
if not_login == 1: if not_login == 1:
not_login = 0 not_login = 0
#print("Could not sign in (you may have entered invalid login credentials)") #print("Could not sign in (you may have entered invalid login credentials)")
#print("Fetching the schedule for today and tomorrow locally\n") #print("Fetching the schedule for this week locally\n")
schedule_tdy_tmr = schedule_tdy_tmr_from_file() schedule_tdy_tmr = schedule_tdy_tmr_from_file()
return schedule_tdy_tmr return schedule_tdy_tmr
@@ -21,7 +19,7 @@ def get_schedule_tdy_tmr(url: str):
soup = BeautifulSoup(html.text, "lxml") soup = BeautifulSoup(html.text, "lxml")
table = soup.find("table", class_="DctTable") table = soup.find("table", id="ctl00_main_boxKalendar_ctl00_ctl04")
rows_odd = table.find_all("tr", class_="RowOdd") rows_odd = table.find_all("tr", class_="RowOdd")
rows_even = table.find_all("tr", class_="RowEven") rows_even = table.find_all("tr", class_="RowEven")
@@ -30,14 +28,20 @@ def get_schedule_tdy_tmr(url: str):
schedule_tdy_tmr = [] schedule_tdy_tmr = []
for i in range(len(rows)): for i in range(len(rows)):
if rows[i].find("td", class_="KuvSuplovanaHodina") is not None and rows[i].find("td", class_="KuvSuplujiciHodina") is None: if rows[i].find("td", class_="KuvSuplovanaHodina") is not None and rows[i].find("td", class_="KuvSuplujiciHodina") is None and rows[i].find("td", class_="KuvSkolniAkceHodina") is None and rows[i].find("td", class_="DctInnerTableType10DataTD") is None:
continue continue
subjects = [] subjects = []
wheres = [] wheres = []
cells = rows[i].find_all("td", attrs={"class": "DctCell"}) cells = rows[i].find_all("td", attrs={"class": "DctCell"})
header_ = table.find("tr").find_all("td", class_="KuvHeaderNadpis")
header = []
for val in header_:
header.append(val.text)
for j in range(len(cells)): for j in range(len(cells)):
if cells[j].text == "": if cells[j].text == "" and header[j] != " - ":
new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'}) new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'})
new_span.string = "Volno" new_span.string = "Volno"
cells[j].append(new_span) cells[j].append(new_span)
@@ -50,22 +54,31 @@ def get_schedule_tdy_tmr(url: str):
subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis") subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis")
temp = [] temp = []
for j in range(len(subjects_)): for j in range(len(subjects_)):
if "KuvSuplovanaHodina" not in subjects_[j].parent["class"]:
temp.append(subjects_[j].text) temp.append(subjects_[j].text)
else:
temp.append("Volno")
subjects = temp subjects = temp
F_con = False F_continue = False
try: try:
while subjects[-1] == "Volno": while subjects[-1] == "Volno":
del subjects[-1] del subjects[-1]
if subjects == []: if subjects == []:
F_con = True F_continue = True
except IndexError: except IndexError:
pass pass
if subjects == []:
F_continue = True
wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText") wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText")
temp = [] temp = []
for j in range(len(wheres_)): for j in range(len(wheres_)):
if len(subjects[j]) < 10: if len(subjects[j]) < 10:
if len(wheres_[j].text[4:]) > 10:
temp.append(" - ")
elif "KuvSuplovanaHodina" not in wheres_[j].parent["class"]:
temp.append(wheres_[j].text[4:]) temp.append(wheres_[j].text[4:])
else: else:
temp.append(" - ") temp.append(" - ")
@@ -74,13 +87,24 @@ def get_schedule_tdy_tmr(url: str):
for j in range(len(cells)): for j in range(len(cells)):
if cells[j].get("colspan") is not None: if cells[j].get("colspan") is not None:
if int(cells[j].get("colspan")) == 2: if int(cells[j].get("colspan")) == 2:
try:
subjects.insert(j, subjects[j]) subjects.insert(j, subjects[j])
wheres.insert(j, wheres[j]) wheres.insert(j, wheres[j])
except IndexError:
pass
for j in range(len(subjects)): for j in range(len(subjects)):
if subjects[j] == "Volno": if subjects[j] == "Volno":
wheres.insert(j, " - ") wheres.insert(j, " - ")
if F_con == False: while True:
if len(subjects) > len(wheres):
del subjects[-1]
elif len(subjects) < len(wheres):
del wheres[-1]
else:
break
if F_continue == False:
schedule_tdy_tmr_row = { schedule_tdy_tmr_row = {
"DAY": day, "DAY": day,
"DATE": date, "DATE": date,
@@ -164,7 +188,7 @@ def show_schedule_tdy_tmr():
print("") print("")
print("--------------------------") print("--------------------------")
print(" Dnešní a zítřejší rozvrh ") print(" Dnesni a zitrejsi rozvrh ")
print("--------------------------\n") print("--------------------------\n")
if schedule == []: if schedule == []:
@@ -196,6 +220,7 @@ def show_schedule_tdy_tmr():
max_len = get_whitespace("WHERES", j+1) max_len = get_whitespace("WHERES", j+1)
whitespace = " " * (max_len - len(schedule[i]["WHERES"][j])) whitespace = " " * (max_len - len(schedule[i]["WHERES"][j]))
print("| " + schedule[i]["WHERES"][j] + whitespace, end=" ") print("| " + schedule[i]["WHERES"][j] + whitespace, end=" ")
print("") print("")
def schedule_tdy_tmr_to_file(schedule=None): def schedule_tdy_tmr_to_file(schedule=None):
@@ -212,15 +237,27 @@ def schedule_tdy_tmr_to_file(schedule=None):
for i in range(len(schedule)): for i in range(len(schedule)):
temp = [] temp = []
try:
temp.append(schedule[i]["DAY"]) temp.append(schedule[i]["DAY"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["SUBJECTS"])): for j in range(len(schedule[i]["SUBJECTS"])):
try:
temp.append(schedule[i]["SUBJECTS"][j]) temp.append(schedule[i]["SUBJECTS"][j])
except KeyError:
temp.append("N/A")
data.append(temp) data.append(temp)
temp = [] temp = []
try:
temp.append(schedule[i]["DATE"]) temp.append(schedule[i]["DATE"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["WHERES"])): for j in range(len(schedule[i]["WHERES"])):
try:
temp.append(schedule[i]["WHERES"][j]) temp.append(schedule[i]["WHERES"][j])
except KeyError:
temp.append("N/A")
data.append(temp) data.append(temp)
writer = csv.writer(f) writer = csv.writer(f)
+35 -7
View File
@@ -46,14 +46,20 @@ def get_schedule_week(url: str):
schedule_week = [] schedule_week = []
for i in range(len(rows)): for i in range(len(rows)):
if rows[i].find("td", class_="KuvSuplovanaHodina") is not None and rows[i].find("td", class_="KuvSuplujiciHodina") is None: if rows[i].find("td", class_="KuvSuplovanaHodina") is not None and rows[i].find("td", class_="KuvSuplujiciHodina") is None and rows[i].find("td", class_="KuvSkolniAkceHodina") is None:
continue continue
subjects = [] subjects = []
wheres = [] wheres = []
cells = rows[i].find_all("td", attrs={"class": "DctCell"}) cells = rows[i].find_all("td", attrs={"class": "DctCell"})
header_ = table.find("tr").find_all("td", class_="KuvHeaderNadpis")
header = []
for val in header_:
header.append(val.text)
for j in range(len(cells)): for j in range(len(cells)):
if cells[j].text == "": if cells[j].text == "" and header[j] != " - ":
new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'}) new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'})
new_span.string = "Volno" new_span.string = "Volno"
cells[j].append(new_span) cells[j].append(new_span)
@@ -66,37 +72,47 @@ def get_schedule_week(url: str):
subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis") subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis")
temp = [] temp = []
for j in range(len(subjects_)): for j in range(len(subjects_)):
if "KuvSuplovanaHodina" not in subjects_[j].parent["class"]:
temp.append(subjects_[j].text) temp.append(subjects_[j].text)
subjects = temp subjects = temp
F_con = False F_continue = False
try: try:
while subjects[-1] == "Volno": while subjects[-1] == "Volno":
del subjects[-1] del subjects[-1]
if subjects == []: if subjects == []:
F_con = True F_continue = True
except IndexError: except IndexError:
pass pass
if subjects == []:
F_continue = True
wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText") wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText")
temp = [] temp = []
for j in range(len(wheres_)): for j in range(len(wheres_)):
try:
if len(subjects[j]) < 10: if len(subjects[j]) < 10:
if len(wheres_[j].text[4:]) > 10:
temp.append(" - ")
elif "KuvSuplovanaHodina" not in wheres_[j].parent["class"]:
temp.append(wheres_[j].text[4:]) temp.append(wheres_[j].text[4:])
else: else:
temp.append(" - ") temp.append(" - ")
except IndexError:
pass
wheres = temp wheres = temp
for j in range(len(cells)): for j in range(len(cells)):
if cells[j].get("colspan") is not None: if cells[j].get("colspan") is not None:
if int(cells[j].get("colspan")) == 2: if int(cells[j].get("colspan")) == 2:
subjects.insert(j, subjects[j]) subjects.insert(j, subjects[j-1])
wheres.insert(j, wheres[j]) wheres.insert(j, wheres[j-1])
for j in range(len(subjects)): for j in range(len(subjects)):
if subjects[j] == "Volno": if subjects[j] == "Volno":
wheres.insert(j, " - ") wheres.insert(j, " - ")
if F_con == False: if F_continue == False:
schedule_week_row = { schedule_week_row = {
"DAY": day, "DAY": day,
"DATE": date, "DATE": date,
@@ -231,15 +247,27 @@ def schedule_week_to_file(schedule=None):
for i in range(len(schedule)): for i in range(len(schedule)):
temp = [] temp = []
try:
temp.append(schedule[i]["DAY"]) temp.append(schedule[i]["DAY"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["SUBJECTS"])): for j in range(len(schedule[i]["SUBJECTS"])):
try:
temp.append(schedule[i]["SUBJECTS"][j]) temp.append(schedule[i]["SUBJECTS"][j])
except KeyError:
temp.append("N/A")
data.append(temp) data.append(temp)
temp = [] temp = []
try:
temp.append(schedule[i]["DATE"]) temp.append(schedule[i]["DATE"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["WHERES"])): for j in range(len(schedule[i]["WHERES"])):
try:
temp.append(schedule[i]["WHERES"][j]) temp.append(schedule[i]["WHERES"][j])
except KeyError:
temp.append("N/A")
data.append(temp) data.append(temp)
writer = csv.writer(f) writer = csv.writer(f)
+15 -4
View File
@@ -7,13 +7,24 @@ if __name__ == "__main__":
user = str(input("Zadejte přihlašovací jméno: ")) user = str(input("Zadejte přihlašovací jméno: "))
pwd = str(input("Zadejte heslo: ")) pwd = str(input("Zadejte heslo: "))
if nw.is_connected() == True: if nw.is_connected() == True:
nw.login(user, pwd) nw.login(user, pwd)
#sw.get_schedule_week("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx") #sw.get_schedule_week("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
sw.show_schedule_week()
#gr.get_grades("/SOL/App/Hodnoceni/KZH001_HodnVypisStud.aspx")
gr.show_grades()
#sw.schedule_week_to_file() #sw.schedule_week_to_file()
#gr.grades_to_file()
#sw.schedule_week_from_file() #sw.schedule_week_from_file()
sw.show_schedule_week()
#gr.get_grades("/SOL/App/Hodnoceni/KZH001_HodnVypisStud.aspx")
#gr.grades_to_file()
#gr.grades_from_file()
gr.show_grades()
#st.get_schedule("/SOL/App/Spolecne/KZZ010_RychlyPrehled.aspx")
#st.schedule_tdy_tmr_to_file()
#st.schedule_tdy_tmr_from_file()
st.show_schedule_tdy_tmr() st.show_schedule_tdy_tmr()