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 bs4 import BeautifulSoup
@@ -11,7 +9,7 @@ def fetch_locally() -> list:
if not_login == 1:
not_login = 0
#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()
return schedule_tdy_tmr
@@ -21,7 +19,7 @@ def get_schedule_tdy_tmr(url: str):
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_even = table.find_all("tr", class_="RowEven")
@@ -30,14 +28,20 @@ def get_schedule_tdy_tmr(url: str):
schedule_tdy_tmr = []
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
subjects = []
wheres = []
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)):
if cells[j].text == "":
if cells[j].text == "" and header[j] != " - ":
new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'})
new_span.string = "Volno"
cells[j].append(new_span)
@@ -50,22 +54,31 @@ def get_schedule_tdy_tmr(url: str):
subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis")
temp = []
for j in range(len(subjects_)):
if "KuvSuplovanaHodina" not in subjects_[j].parent["class"]:
temp.append(subjects_[j].text)
else:
temp.append("Volno")
subjects = temp
F_con = False
F_continue = False
try:
while subjects[-1] == "Volno":
del subjects[-1]
if subjects == []:
F_con = True
F_continue = True
except IndexError:
pass
if subjects == []:
F_continue = True
wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText")
temp = []
for j in range(len(wheres_)):
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:])
else:
temp.append(" - ")
@@ -74,13 +87,24 @@ def get_schedule_tdy_tmr(url: str):
for j in range(len(cells)):
if cells[j].get("colspan") is not None:
if int(cells[j].get("colspan")) == 2:
try:
subjects.insert(j, subjects[j])
wheres.insert(j, wheres[j])
except IndexError:
pass
for j in range(len(subjects)):
if subjects[j] == "Volno":
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 = {
"DAY": day,
"DATE": date,
@@ -164,7 +188,7 @@ def show_schedule_tdy_tmr():
print("")
print("--------------------------")
print(" Dnešní a zítřejší rozvrh ")
print(" Dnesni a zitrejsi rozvrh ")
print("--------------------------\n")
if schedule == []:
@@ -196,6 +220,7 @@ def show_schedule_tdy_tmr():
max_len = get_whitespace("WHERES", j+1)
whitespace = " " * (max_len - len(schedule[i]["WHERES"][j]))
print("| " + schedule[i]["WHERES"][j] + whitespace, end=" ")
print("")
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)):
temp = []
try:
temp.append(schedule[i]["DAY"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["SUBJECTS"])):
try:
temp.append(schedule[i]["SUBJECTS"][j])
except KeyError:
temp.append("N/A")
data.append(temp)
temp = []
try:
temp.append(schedule[i]["DATE"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["WHERES"])):
try:
temp.append(schedule[i]["WHERES"][j])
except KeyError:
temp.append("N/A")
data.append(temp)
writer = csv.writer(f)
+35 -7
View File
@@ -46,14 +46,20 @@ def get_schedule_week(url: str):
schedule_week = []
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
subjects = []
wheres = []
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)):
if cells[j].text == "":
if cells[j].text == "" and header[j] != " - ":
new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'})
new_span.string = "Volno"
cells[j].append(new_span)
@@ -66,37 +72,47 @@ def get_schedule_week(url: str):
subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis")
temp = []
for j in range(len(subjects_)):
if "KuvSuplovanaHodina" not in subjects_[j].parent["class"]:
temp.append(subjects_[j].text)
subjects = temp
F_con = False
F_continue = False
try:
while subjects[-1] == "Volno":
del subjects[-1]
if subjects == []:
F_con = True
F_continue = True
except IndexError:
pass
if subjects == []:
F_continue = True
wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText")
temp = []
for j in range(len(wheres_)):
try:
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:])
else:
temp.append(" - ")
except IndexError:
pass
wheres = temp
for j in range(len(cells)):
if cells[j].get("colspan") is not None:
if int(cells[j].get("colspan")) == 2:
subjects.insert(j, subjects[j])
wheres.insert(j, wheres[j])
subjects.insert(j, subjects[j-1])
wheres.insert(j, wheres[j-1])
for j in range(len(subjects)):
if subjects[j] == "Volno":
wheres.insert(j, " - ")
if F_con == False:
if F_continue == False:
schedule_week_row = {
"DAY": day,
"DATE": date,
@@ -231,15 +247,27 @@ def schedule_week_to_file(schedule=None):
for i in range(len(schedule)):
temp = []
try:
temp.append(schedule[i]["DAY"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["SUBJECTS"])):
try:
temp.append(schedule[i]["SUBJECTS"][j])
except KeyError:
temp.append("N/A")
data.append(temp)
temp = []
try:
temp.append(schedule[i]["DATE"])
except KeyError:
temp.append("N/A")
for j in range(len(schedule[i]["WHERES"])):
try:
temp.append(schedule[i]["WHERES"][j])
except KeyError:
temp.append("N/A")
data.append(temp)
writer = csv.writer(f)
+15 -4
View File
@@ -7,13 +7,24 @@ if __name__ == "__main__":
user = str(input("Zadejte přihlašovací jméno: "))
pwd = str(input("Zadejte heslo: "))
if nw.is_connected() == True:
nw.login(user, pwd)
#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()
#gr.grades_to_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()