fix: general bugfixes, display errors
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
|
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
|
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
|
+241
-204
@@ -1,268 +1,305 @@
|
||||
# fetch the schedule for today and tomorrow from the landing page of ŠOL
|
||||
|
||||
from lib import networking as nw
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
not_login = 0
|
||||
|
||||
def fetch_locally() -> list:
|
||||
global not_login
|
||||
global not_login
|
||||
|
||||
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")
|
||||
schedule_tdy_tmr = schedule_tdy_tmr_from_file()
|
||||
return schedule_tdy_tmr
|
||||
if not_login == 1:
|
||||
not_login = 0
|
||||
#print("Could not sign in (you may have entered invalid login credentials)")
|
||||
#print("Fetching the schedule for this week locally\n")
|
||||
schedule_tdy_tmr = schedule_tdy_tmr_from_file()
|
||||
return schedule_tdy_tmr
|
||||
|
||||
def get_schedule_tdy_tmr(url: str):
|
||||
try:
|
||||
html = nw.get_html_from(url)
|
||||
try:
|
||||
html = nw.get_html_from(url)
|
||||
|
||||
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_even = table.find_all("tr", class_="RowEven")
|
||||
rows = rows_odd + rows_even
|
||||
rows_odd = table.find_all("tr", class_="RowOdd")
|
||||
rows_even = table.find_all("tr", class_="RowEven")
|
||||
rows = rows_odd + rows_even
|
||||
|
||||
schedule_tdy_tmr = []
|
||||
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:
|
||||
continue
|
||||
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 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"})
|
||||
for j in range(len(cells)):
|
||||
if cells[j].text == "":
|
||||
new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'})
|
||||
new_span.string = "Volno"
|
||||
cells[j].append(new_span)
|
||||
subjects = []
|
||||
wheres = []
|
||||
cells = rows[i].find_all("td", attrs={"class": "DctCell"})
|
||||
|
||||
if rows[i].find("td", class_="KuvHeaderNadpis") is not None:
|
||||
day = rows[i].find("td", class_="KuvHeaderNadpis").text
|
||||
header_ = table.find("tr").find_all("td", class_="KuvHeaderNadpis")
|
||||
header = []
|
||||
for val in header_:
|
||||
header.append(val.text)
|
||||
|
||||
date = rows[i].find("td", class_="KuvHeaderText").text
|
||||
for j in range(len(cells)):
|
||||
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)
|
||||
|
||||
subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis")
|
||||
temp = []
|
||||
for j in range(len(subjects_)):
|
||||
temp.append(subjects_[j].text)
|
||||
subjects = temp
|
||||
if rows[i].find("td", class_="KuvHeaderNadpis") is not None:
|
||||
day = rows[i].find("td", class_="KuvHeaderNadpis").text
|
||||
|
||||
F_con = False
|
||||
try:
|
||||
while subjects[-1] == "Volno":
|
||||
del subjects[-1]
|
||||
if subjects == []:
|
||||
F_con = True
|
||||
except IndexError:
|
||||
pass
|
||||
date = rows[i].find("td", class_="KuvHeaderText").text
|
||||
|
||||
wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText")
|
||||
temp = []
|
||||
for j in range(len(wheres_)):
|
||||
if len(subjects[j]) < 10:
|
||||
temp.append(wheres_[j].text[4:])
|
||||
else:
|
||||
temp.append(" - ")
|
||||
wheres = temp
|
||||
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
|
||||
|
||||
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])
|
||||
for j in range(len(subjects)):
|
||||
if subjects[j] == "Volno":
|
||||
wheres.insert(j, " - ")
|
||||
F_continue = False
|
||||
try:
|
||||
while subjects[-1] == "Volno":
|
||||
del subjects[-1]
|
||||
if subjects == []:
|
||||
F_continue = True
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
if F_con == False:
|
||||
schedule_tdy_tmr_row = {
|
||||
"DAY": day,
|
||||
"DATE": date,
|
||||
"SUBJECTS": subjects,
|
||||
"WHERES": wheres
|
||||
}
|
||||
if subjects == []:
|
||||
F_continue = True
|
||||
|
||||
schedule_tdy_tmr.append(schedule_tdy_tmr_row)
|
||||
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(" - ")
|
||||
wheres = temp
|
||||
|
||||
return schedule_tdy_tmr
|
||||
except AttributeError:
|
||||
global not_login
|
||||
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, " - ")
|
||||
|
||||
not_login = 1
|
||||
schedule = fetch_locally()
|
||||
return schedule
|
||||
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,
|
||||
"SUBJECTS": subjects,
|
||||
"WHERES": wheres
|
||||
}
|
||||
|
||||
schedule_tdy_tmr.append(schedule_tdy_tmr_row)
|
||||
|
||||
return schedule_tdy_tmr
|
||||
except AttributeError:
|
||||
global not_login
|
||||
|
||||
not_login = 1
|
||||
schedule = fetch_locally()
|
||||
return schedule
|
||||
|
||||
def schedule_tdy_tmr_from_file_to_list():
|
||||
schedule = []
|
||||
schedule_ = []
|
||||
schedule = []
|
||||
schedule_ = []
|
||||
|
||||
try:
|
||||
with open("src/lib/data/schedule_tdy_tmr.csv") as f:
|
||||
import csv
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
temp = []
|
||||
for col in row:
|
||||
temp.append(col.strip())
|
||||
schedule_.append(temp)
|
||||
try:
|
||||
with open("src/lib/data/schedule_tdy_tmr.csv") as f:
|
||||
import csv
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
temp = []
|
||||
for col in row:
|
||||
temp.append(col.strip())
|
||||
schedule_.append(temp)
|
||||
|
||||
for i in range(0, len(schedule_), 2):
|
||||
del schedule_[i][0]
|
||||
for i in range(0, len(schedule_), 2):
|
||||
del schedule_[i][0]
|
||||
|
||||
temp = []
|
||||
for i in range(1, len(schedule_), 2):
|
||||
temp.append(schedule_[i][0])
|
||||
del schedule_[i][0]
|
||||
schedule.append(temp)
|
||||
temp = []
|
||||
for i in range(1, len(schedule_), 2):
|
||||
temp.append(schedule_[i][0])
|
||||
del schedule_[i][0]
|
||||
schedule.append(temp)
|
||||
|
||||
for i in range(10):
|
||||
temp = []
|
||||
for j in range(10):
|
||||
try:
|
||||
temp.append(schedule_[j][0])
|
||||
del schedule_[j][0]
|
||||
except IndexError:
|
||||
pass
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_tdy_tmr.csv file found\n")
|
||||
for i in range(10):
|
||||
temp = []
|
||||
for j in range(10):
|
||||
try:
|
||||
temp.append(schedule_[j][0])
|
||||
del schedule_[j][0]
|
||||
except IndexError:
|
||||
pass
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_tdy_tmr.csv file found\n")
|
||||
|
||||
return schedule
|
||||
return schedule
|
||||
|
||||
def get_whitespace(key: str, idx=0) -> int:
|
||||
schedule = schedule_tdy_tmr_from_file_to_list()
|
||||
max_len = 0
|
||||
schedule = schedule_tdy_tmr_from_file_to_list()
|
||||
max_len = 0
|
||||
|
||||
if key == "DATE":
|
||||
try:
|
||||
max_len = len(max(schedule[0], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
elif key == "WHERES":
|
||||
try:
|
||||
max_len = len(max(schedule[idx], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
if key == "DATE":
|
||||
try:
|
||||
max_len = len(max(schedule[0], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
elif key == "WHERES":
|
||||
try:
|
||||
max_len = len(max(schedule[idx], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return max_len
|
||||
return max_len
|
||||
|
||||
def show_schedule_tdy_tmr():
|
||||
# if there is internet access, load stuff from the web
|
||||
# if not, load the schedule.csv file
|
||||
if nw.is_connected() == True:
|
||||
schedule = get_schedule_tdy_tmr("/SOL/App/Spolecne/KZZ010_RychlyPrehled.aspx")
|
||||
schedule_tdy_tmr_to_file(schedule)
|
||||
else:
|
||||
schedule = schedule_tdy_tmr_from_file()
|
||||
# if there is internet access, load stuff from the web
|
||||
# if not, load the schedule.csv file
|
||||
if nw.is_connected() == True:
|
||||
schedule = get_schedule_tdy_tmr("/SOL/App/Spolecne/KZZ010_RychlyPrehled.aspx")
|
||||
schedule_tdy_tmr_to_file(schedule)
|
||||
else:
|
||||
schedule = schedule_tdy_tmr_from_file()
|
||||
|
||||
print("")
|
||||
print("")
|
||||
|
||||
print("--------------------------")
|
||||
print(" Dnešní a zítřejší rozvrh ")
|
||||
print("--------------------------\n")
|
||||
print("--------------------------")
|
||||
print(" Dnesni a zitrejsi rozvrh ")
|
||||
print("--------------------------\n")
|
||||
|
||||
if schedule == []:
|
||||
print("N/A\n")
|
||||
import os
|
||||
if schedule == []:
|
||||
print("N/A\n")
|
||||
import os
|
||||
|
||||
if os.path.exists("src/lib/data/schedule_tdy_tmr.csv"):
|
||||
os.remove("src/lib/data/schedule_tdy_tmr.csv")
|
||||
return
|
||||
if os.path.exists("src/lib/data/schedule_tdy_tmr.csv"):
|
||||
os.remove("src/lib/data/schedule_tdy_tmr.csv")
|
||||
return
|
||||
|
||||
for i in range(len(schedule)):
|
||||
max_len = get_whitespace("DATE")
|
||||
for i in range(len(schedule)):
|
||||
max_len = get_whitespace("DATE")
|
||||
|
||||
whitespace = " " * (max_len - len(schedule[i]["DAY"]))
|
||||
print(schedule[i]["DAY"] + whitespace, end=" ")
|
||||
whitespace = " " * (max_len - len(schedule[i]["DAY"]))
|
||||
print(schedule[i]["DAY"] + whitespace, end=" ")
|
||||
|
||||
for j in range(len(schedule[i]["SUBJECTS"])):
|
||||
max_len = get_whitespace("WHERES", j+1)
|
||||
whitespace = " " * (max_len - len(schedule[i]["SUBJECTS"][j]))
|
||||
print("| " + schedule[i]["SUBJECTS"][j] + whitespace, end=" ")
|
||||
for j in range(len(schedule[i]["SUBJECTS"])):
|
||||
max_len = get_whitespace("WHERES", j+1)
|
||||
whitespace = " " * (max_len - len(schedule[i]["SUBJECTS"][j]))
|
||||
print("| " + schedule[i]["SUBJECTS"][j] + whitespace, end=" ")
|
||||
|
||||
print("")
|
||||
print("")
|
||||
|
||||
max_len = get_whitespace("DATE")
|
||||
whitespace = " " * (max_len - len(schedule[i]["DATE"]))
|
||||
print(schedule[i]["DATE"] + whitespace, end=" ")
|
||||
max_len = get_whitespace("DATE")
|
||||
whitespace = " " * (max_len - len(schedule[i]["DATE"]))
|
||||
print(schedule[i]["DATE"] + whitespace, end=" ")
|
||||
|
||||
for j in range(len(schedule[i]["WHERES"])):
|
||||
max_len = get_whitespace("WHERES", j+1)
|
||||
whitespace = " " * (max_len - len(schedule[i]["WHERES"][j]))
|
||||
print("| " + schedule[i]["WHERES"][j] + whitespace, end=" ")
|
||||
print("")
|
||||
for j in range(len(schedule[i]["WHERES"])):
|
||||
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):
|
||||
import csv
|
||||
if schedule is None:
|
||||
try:
|
||||
schedule = get_schedule_tdy_tmr("/SOL/App/Spolecne/KZZ010_RychlyPrehled.aspx")
|
||||
except Exception:
|
||||
print("An error occured, you probably can't access the internet right now")
|
||||
return
|
||||
import csv
|
||||
if schedule is None:
|
||||
try:
|
||||
schedule = get_schedule_tdy_tmr("/SOL/App/Spolecne/KZZ010_RychlyPrehled.aspx")
|
||||
except Exception:
|
||||
print("An error occured, you probably can't access the internet right now")
|
||||
return
|
||||
|
||||
with open("src/lib/data/schedule_tdy_tmr.csv", mode="w", newline="") as f:
|
||||
data = []
|
||||
with open("src/lib/data/schedule_tdy_tmr.csv", mode="w", newline="") as f:
|
||||
data = []
|
||||
|
||||
for i in range(len(schedule)):
|
||||
temp = []
|
||||
temp.append(schedule[i]["DAY"])
|
||||
for j in range(len(schedule[i]["SUBJECTS"])):
|
||||
temp.append(schedule[i]["SUBJECTS"][j])
|
||||
data.append(temp)
|
||||
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 = []
|
||||
temp.append(schedule[i]["DATE"])
|
||||
for j in range(len(schedule[i]["WHERES"])):
|
||||
temp.append(schedule[i]["WHERES"][j])
|
||||
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)
|
||||
for row in data:
|
||||
writer.writerow(row)
|
||||
writer = csv.writer(f)
|
||||
for row in data:
|
||||
writer.writerow(row)
|
||||
|
||||
def schedule_tdy_tmr_from_file() -> list:
|
||||
import csv
|
||||
schedule = []
|
||||
import csv
|
||||
schedule = []
|
||||
|
||||
try:
|
||||
with open("src/lib/data/schedule_tdy_tmr.csv", mode="r") as f:
|
||||
reader = csv.reader(f)
|
||||
rows = []
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
try:
|
||||
with open("src/lib/data/schedule_tdy_tmr.csv", mode="r") as f:
|
||||
reader = csv.reader(f)
|
||||
rows = []
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
|
||||
for row in range(0, len(rows), 2):
|
||||
temp = {}
|
||||
for row in range(0, len(rows), 2):
|
||||
temp = {}
|
||||
|
||||
temp["DAY"] = rows[row][0]
|
||||
temp["DAY"] = rows[row][0]
|
||||
|
||||
try:
|
||||
temp["DATE"] = rows[row+1][0]
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
temp["DATE"] = rows[row+1][0]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
subjects = []
|
||||
for i in range(1, len(rows[row])):
|
||||
subjects.append(rows[row][i])
|
||||
temp["SUBJECTS"] = subjects
|
||||
subjects = []
|
||||
for i in range(1, len(rows[row])):
|
||||
subjects.append(rows[row][i])
|
||||
temp["SUBJECTS"] = subjects
|
||||
|
||||
wheres = []
|
||||
try:
|
||||
for i in range(1, len(rows[row+1])):
|
||||
wheres.append(rows[row+1][i])
|
||||
except IndexError:
|
||||
pass
|
||||
temp["WHERES"] = wheres
|
||||
wheres = []
|
||||
try:
|
||||
for i in range(1, len(rows[row+1])):
|
||||
wheres.append(rows[row+1][i])
|
||||
except IndexError:
|
||||
pass
|
||||
temp["WHERES"] = wheres
|
||||
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_tdy_tmr.csv file found\n")
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_tdy_tmr.csv file found\n")
|
||||
|
||||
return schedule
|
||||
return schedule
|
||||
|
||||
+244
-216
@@ -4,284 +4,312 @@ from bs4 import BeautifulSoup
|
||||
not_login = 0
|
||||
|
||||
def fetch_locally() -> list:
|
||||
global not_login
|
||||
global not_login
|
||||
|
||||
if not_login == 1:
|
||||
not_login = 0
|
||||
#print("Could not sign in (you may have entered invalid login credentials)")
|
||||
#print("Fetching the schedule for this week locally\n")
|
||||
schedule_week = schedule_week_from_file()
|
||||
return schedule_week
|
||||
if not_login == 1:
|
||||
not_login = 0
|
||||
#print("Could not sign in (you may have entered invalid login credentials)")
|
||||
#print("Fetching the schedule for this week locally\n")
|
||||
schedule_week = schedule_week_from_file()
|
||||
return schedule_week
|
||||
|
||||
|
||||
def sort_schedule_week(schedule_week: list[dict]) -> list[dict]:
|
||||
sorted_schedule_week: list[dict] = [{}, {}, {}, {}, {}]
|
||||
sorted_schedule_week: list[dict] = [{}, {}, {}, {}, {}]
|
||||
|
||||
for i in range(len(schedule_week)):
|
||||
if schedule_week[i]["DAY"] == "Po":
|
||||
sorted_schedule_week[0] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "Út":
|
||||
sorted_schedule_week[1] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "St":
|
||||
sorted_schedule_week[2] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "Čt":
|
||||
sorted_schedule_week[3] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "Pá":
|
||||
sorted_schedule_week[4] = schedule_week[i]
|
||||
for i in range(len(schedule_week)):
|
||||
if schedule_week[i]["DAY"] == "Po":
|
||||
sorted_schedule_week[0] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "Út":
|
||||
sorted_schedule_week[1] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "St":
|
||||
sorted_schedule_week[2] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "Čt":
|
||||
sorted_schedule_week[3] = schedule_week[i]
|
||||
if schedule_week[i]["DAY"] == "Pá":
|
||||
sorted_schedule_week[4] = schedule_week[i]
|
||||
|
||||
return sorted_schedule_week
|
||||
return sorted_schedule_week
|
||||
|
||||
def get_schedule_week(url: str):
|
||||
try:
|
||||
html = nw.get_html_from(url)
|
||||
try:
|
||||
html = nw.get_html_from(url)
|
||||
|
||||
soup = BeautifulSoup(html.text, "lxml")
|
||||
soup = BeautifulSoup(html.text, "lxml")
|
||||
|
||||
table = soup.find("table", id="CCADynamicCalendarTable")
|
||||
table = soup.find("table", id="CCADynamicCalendarTable")
|
||||
|
||||
rows_odd = table.find_all("tr", class_="RowOdd")
|
||||
rows_even = table.find_all("tr", class_="RowEven")
|
||||
rows = rows_odd + rows_even
|
||||
rows_odd = table.find_all("tr", class_="RowOdd")
|
||||
rows_even = table.find_all("tr", class_="RowEven")
|
||||
rows = rows_odd + rows_even
|
||||
|
||||
schedule_week = []
|
||||
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:
|
||||
continue
|
||||
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 and rows[i].find("td", class_="KuvSkolniAkceHodina") is None:
|
||||
continue
|
||||
|
||||
subjects = []
|
||||
wheres = []
|
||||
cells = rows[i].find_all("td", attrs={"class": "DctCell"})
|
||||
for j in range(len(cells)):
|
||||
if cells[j].text == "":
|
||||
new_span = soup.new_tag("span", attrs={'class': 'KuvBunkaRozvrhNadpis'})
|
||||
new_span.string = "Volno"
|
||||
cells[j].append(new_span)
|
||||
subjects = []
|
||||
wheres = []
|
||||
cells = rows[i].find_all("td", attrs={"class": "DctCell"})
|
||||
|
||||
if rows[i].find("td", class_="KuvHeaderNadpis") is not None:
|
||||
day = rows[i].find("td", class_="KuvHeaderNadpis").text
|
||||
header_ = table.find("tr").find_all("td", class_="KuvHeaderNadpis")
|
||||
header = []
|
||||
for val in header_:
|
||||
header.append(val.text)
|
||||
|
||||
date = rows[i].find("td", class_="KuvHeaderText").text
|
||||
for j in range(len(cells)):
|
||||
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)
|
||||
|
||||
subjects_ = rows[i].find_all("span", class_="KuvBunkaRozvrhNadpis")
|
||||
temp = []
|
||||
for j in range(len(subjects_)):
|
||||
temp.append(subjects_[j].text)
|
||||
subjects = temp
|
||||
if rows[i].find("td", class_="KuvHeaderNadpis") is not None:
|
||||
day = rows[i].find("td", class_="KuvHeaderNadpis").text
|
||||
|
||||
F_con = False
|
||||
try:
|
||||
while subjects[-1] == "Volno":
|
||||
del subjects[-1]
|
||||
if subjects == []:
|
||||
F_con = True
|
||||
except IndexError:
|
||||
pass
|
||||
date = rows[i].find("td", class_="KuvHeaderText").text
|
||||
|
||||
wheres_ = rows[i].find_all("span", class_="KuvBunkaRozvrhText")
|
||||
temp = []
|
||||
for j in range(len(wheres_)):
|
||||
if len(subjects[j]) < 10:
|
||||
temp.append(wheres_[j].text[4:])
|
||||
else:
|
||||
temp.append(" - ")
|
||||
wheres = temp
|
||||
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
|
||||
|
||||
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])
|
||||
for j in range(len(subjects)):
|
||||
if subjects[j] == "Volno":
|
||||
wheres.insert(j, " - ")
|
||||
F_continue = False
|
||||
try:
|
||||
while subjects[-1] == "Volno":
|
||||
del subjects[-1]
|
||||
if subjects == []:
|
||||
F_continue = True
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
if F_con == False:
|
||||
schedule_week_row = {
|
||||
"DAY": day,
|
||||
"DATE": date,
|
||||
"SUBJECTS": subjects,
|
||||
"WHERES": wheres
|
||||
}
|
||||
if subjects == []:
|
||||
F_continue = True
|
||||
|
||||
schedule_week.append(schedule_week_row)
|
||||
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
|
||||
|
||||
sorted_schedule_week = sort_schedule_week(schedule_week)
|
||||
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-1])
|
||||
wheres.insert(j, wheres[j-1])
|
||||
for j in range(len(subjects)):
|
||||
if subjects[j] == "Volno":
|
||||
wheres.insert(j, " - ")
|
||||
|
||||
return sorted_schedule_week
|
||||
except AttributeError:
|
||||
global not_login
|
||||
if F_continue == False:
|
||||
schedule_week_row = {
|
||||
"DAY": day,
|
||||
"DATE": date,
|
||||
"SUBJECTS": subjects,
|
||||
"WHERES": wheres
|
||||
}
|
||||
|
||||
not_login = 1
|
||||
schedule = fetch_locally()
|
||||
return schedule
|
||||
schedule_week.append(schedule_week_row)
|
||||
|
||||
sorted_schedule_week = sort_schedule_week(schedule_week)
|
||||
|
||||
return sorted_schedule_week
|
||||
except AttributeError:
|
||||
global not_login
|
||||
|
||||
not_login = 1
|
||||
schedule = fetch_locally()
|
||||
return schedule
|
||||
|
||||
def schedule_week_from_file_to_list():
|
||||
schedule = []
|
||||
schedule_ = []
|
||||
schedule = []
|
||||
schedule_ = []
|
||||
|
||||
try:
|
||||
with open("src/lib/data/schedule_week.csv") as f:
|
||||
import csv
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
temp = []
|
||||
for col in row:
|
||||
temp.append(col.strip())
|
||||
schedule_.append(temp)
|
||||
try:
|
||||
with open("src/lib/data/schedule_week.csv") as f:
|
||||
import csv
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
temp = []
|
||||
for col in row:
|
||||
temp.append(col.strip())
|
||||
schedule_.append(temp)
|
||||
|
||||
for i in range(0, len(schedule_), 2):
|
||||
del schedule_[i][0]
|
||||
for i in range(0, len(schedule_), 2):
|
||||
del schedule_[i][0]
|
||||
|
||||
temp = []
|
||||
for i in range(1, len(schedule_), 2):
|
||||
temp.append(schedule_[i][0])
|
||||
del schedule_[i][0]
|
||||
schedule.append(temp)
|
||||
temp = []
|
||||
for i in range(1, len(schedule_), 2):
|
||||
temp.append(schedule_[i][0])
|
||||
del schedule_[i][0]
|
||||
schedule.append(temp)
|
||||
|
||||
for i in range(10):
|
||||
temp = []
|
||||
for j in range(10):
|
||||
try:
|
||||
temp.append(schedule_[j][0])
|
||||
del schedule_[j][0]
|
||||
except IndexError:
|
||||
pass
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_week.csv file found\n")
|
||||
for i in range(10):
|
||||
temp = []
|
||||
for j in range(10):
|
||||
try:
|
||||
temp.append(schedule_[j][0])
|
||||
del schedule_[j][0]
|
||||
except IndexError:
|
||||
pass
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_week.csv file found\n")
|
||||
|
||||
return schedule
|
||||
return schedule
|
||||
|
||||
def get_whitespace(key: str, idx=0) -> int:
|
||||
schedule = schedule_week_from_file_to_list()
|
||||
max_len = 0
|
||||
schedule = schedule_week_from_file_to_list()
|
||||
max_len = 0
|
||||
|
||||
if key == "DATE":
|
||||
try:
|
||||
max_len = len(max(schedule[0], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
elif key == "WHERES":
|
||||
try:
|
||||
max_len = len(max(schedule[idx], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
if key == "DATE":
|
||||
try:
|
||||
max_len = len(max(schedule[0], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
elif key == "WHERES":
|
||||
try:
|
||||
max_len = len(max(schedule[idx], key=len))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return max_len
|
||||
return max_len
|
||||
|
||||
def show_schedule_week():
|
||||
# if there is internet access, load stuff from the web
|
||||
# if not, load the schedule.csv file
|
||||
if nw.is_connected() == True:
|
||||
schedule = get_schedule_week("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
|
||||
schedule_week_to_file(schedule)
|
||||
else:
|
||||
schedule = schedule_week_from_file()
|
||||
# if there is internet access, load stuff from the web
|
||||
# if not, load the schedule.csv file
|
||||
if nw.is_connected() == True:
|
||||
schedule = get_schedule_week("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
|
||||
schedule_week_to_file(schedule)
|
||||
else:
|
||||
schedule = schedule_week_from_file()
|
||||
|
||||
print("")
|
||||
print("")
|
||||
|
||||
print("----------------")
|
||||
print(" Týdenní rozvrh ")
|
||||
print("----------------\n")
|
||||
print("----------------")
|
||||
print(" Týdenní rozvrh ")
|
||||
print("----------------\n")
|
||||
|
||||
if schedule == []:
|
||||
print("N/A\n")
|
||||
import os
|
||||
if schedule == []:
|
||||
print("N/A\n")
|
||||
import os
|
||||
|
||||
if os.path.exists("src/lib/data/schedule_week.csv"):
|
||||
os.remove("src/lib/data/schedule_week.csv")
|
||||
return
|
||||
if os.path.exists("src/lib/data/schedule_week.csv"):
|
||||
os.remove("src/lib/data/schedule_week.csv")
|
||||
return
|
||||
|
||||
for i in range(len(schedule)):
|
||||
max_len = get_whitespace("DATE")
|
||||
for i in range(len(schedule)):
|
||||
max_len = get_whitespace("DATE")
|
||||
|
||||
whitespace = " " * (max_len - len(schedule[i]["DAY"]))
|
||||
print(schedule[i]["DAY"] + whitespace, end=" ")
|
||||
whitespace = " " * (max_len - len(schedule[i]["DAY"]))
|
||||
print(schedule[i]["DAY"] + whitespace, end=" ")
|
||||
|
||||
for j in range(len(schedule[i]["SUBJECTS"])):
|
||||
max_len = get_whitespace("WHERES", j+1)
|
||||
whitespace = " " * (max_len - len(schedule[i]["SUBJECTS"][j]))
|
||||
print("| " + schedule[i]["SUBJECTS"][j] + whitespace, end=" ")
|
||||
for j in range(len(schedule[i]["SUBJECTS"])):
|
||||
max_len = get_whitespace("WHERES", j+1)
|
||||
whitespace = " " * (max_len - len(schedule[i]["SUBJECTS"][j]))
|
||||
print("| " + schedule[i]["SUBJECTS"][j] + whitespace, end=" ")
|
||||
|
||||
print("")
|
||||
print("")
|
||||
|
||||
max_len = get_whitespace("DATE")
|
||||
whitespace = " " * (max_len - len(schedule[i]["DATE"]))
|
||||
print(schedule[i]["DATE"] + whitespace, end=" ")
|
||||
max_len = get_whitespace("DATE")
|
||||
whitespace = " " * (max_len - len(schedule[i]["DATE"]))
|
||||
print(schedule[i]["DATE"] + whitespace, end=" ")
|
||||
|
||||
for j in range(len(schedule[i]["WHERES"])):
|
||||
max_len = get_whitespace("WHERES", j+1)
|
||||
whitespace = " " * (max_len - len(schedule[i]["WHERES"][j]))
|
||||
print("| " + schedule[i]["WHERES"][j] + whitespace, end=" ")
|
||||
for j in range(len(schedule[i]["WHERES"])):
|
||||
max_len = get_whitespace("WHERES", j+1)
|
||||
whitespace = " " * (max_len - len(schedule[i]["WHERES"][j]))
|
||||
print("| " + schedule[i]["WHERES"][j] + whitespace, end=" ")
|
||||
|
||||
print("")
|
||||
print("")
|
||||
|
||||
def schedule_week_to_file(schedule=None):
|
||||
import csv
|
||||
if schedule is None:
|
||||
try:
|
||||
schedule = get_schedule_week("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
|
||||
except Exception:
|
||||
print("An error occured, you probably can't access the internet right now")
|
||||
return
|
||||
import csv
|
||||
if schedule is None:
|
||||
try:
|
||||
schedule = get_schedule_week("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
|
||||
except Exception:
|
||||
print("An error occured, you probably can't access the internet right now")
|
||||
return
|
||||
|
||||
with open("src/lib/data/schedule_week.csv", mode="w", newline="") as f:
|
||||
data = []
|
||||
with open("src/lib/data/schedule_week.csv", mode="w", newline="") as f:
|
||||
data = []
|
||||
|
||||
for i in range(len(schedule)):
|
||||
temp = []
|
||||
temp.append(schedule[i]["DAY"])
|
||||
for j in range(len(schedule[i]["SUBJECTS"])):
|
||||
temp.append(schedule[i]["SUBJECTS"][j])
|
||||
data.append(temp)
|
||||
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 = []
|
||||
temp.append(schedule[i]["DATE"])
|
||||
for j in range(len(schedule[i]["WHERES"])):
|
||||
temp.append(schedule[i]["WHERES"][j])
|
||||
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)
|
||||
for row in data:
|
||||
writer.writerow(row)
|
||||
writer = csv.writer(f)
|
||||
for row in data:
|
||||
writer.writerow(row)
|
||||
|
||||
def schedule_week_from_file() -> list:
|
||||
import csv
|
||||
schedule = []
|
||||
import csv
|
||||
schedule = []
|
||||
|
||||
try:
|
||||
with open("src/lib/data/schedule_week.csv", mode="r") as f:
|
||||
reader = csv.reader(f)
|
||||
rows = []
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
try:
|
||||
with open("src/lib/data/schedule_week.csv", mode="r") as f:
|
||||
reader = csv.reader(f)
|
||||
rows = []
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
|
||||
for row in range(0, len(rows), 2):
|
||||
temp = {}
|
||||
for row in range(0, len(rows), 2):
|
||||
temp = {}
|
||||
|
||||
temp["DAY"] = rows[row][0]
|
||||
temp["DAY"] = rows[row][0]
|
||||
|
||||
try:
|
||||
temp["DATE"] = rows[row+1][0]
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
temp["DATE"] = rows[row+1][0]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
subjects = []
|
||||
for i in range(1, len(rows[row])):
|
||||
subjects.append(rows[row][i])
|
||||
temp["SUBJECTS"] = subjects
|
||||
subjects = []
|
||||
for i in range(1, len(rows[row])):
|
||||
subjects.append(rows[row][i])
|
||||
temp["SUBJECTS"] = subjects
|
||||
|
||||
wheres = []
|
||||
try:
|
||||
for i in range(1, len(rows[row+1])):
|
||||
wheres.append(rows[row+1][i])
|
||||
except IndexError:
|
||||
pass
|
||||
temp["WHERES"] = wheres
|
||||
wheres = []
|
||||
try:
|
||||
for i in range(1, len(rows[row+1])):
|
||||
wheres.append(rows[row+1][i])
|
||||
except IndexError:
|
||||
pass
|
||||
temp["WHERES"] = wheres
|
||||
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_week.csv file found\n")
|
||||
schedule.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No schedule_week.csv file found\n")
|
||||
|
||||
return schedule
|
||||
return schedule
|
||||
|
||||
+23
-12
@@ -4,16 +4,27 @@ from lib import schedule_week as sw
|
||||
from lib import schedule_tdy_tmr as st
|
||||
|
||||
if __name__ == "__main__":
|
||||
user = str(input("Zadejte přihlašovací jméno: "))
|
||||
pwd = str(input("Zadejte heslo: "))
|
||||
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()
|
||||
st.show_schedule_tdy_tmr()
|
||||
|
||||
if nw.is_connected() == True:
|
||||
nw.login(user, pwd)
|
||||
|
||||
|
||||
#sw.get_schedule_week("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
|
||||
#sw.schedule_week_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()
|
||||
|
||||
Reference in New Issue
Block a user