Wed Jun 21 15:43:39 CEST 2023
This commit is contained in:
@@ -1 +0,0 @@
|
||||
|
||||
|
|
@@ -1 +0,0 @@
|
||||
|
||||
|
|
@@ -1 +0,0 @@
|
||||
|
||||
|
|
+130
-118
@@ -5,154 +5,166 @@ import os
|
||||
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 grades locally\n")
|
||||
grades = grades_from_file()
|
||||
return grades
|
||||
if not_login == 1:
|
||||
not_login = 0
|
||||
#print("Could not sign in (you may have entered invalid login credentials)")
|
||||
#print("Fetching grades locally\n")
|
||||
grades = grades_from_file()
|
||||
return grades
|
||||
|
||||
|
||||
"""
|
||||
# deprecated
|
||||
def get_avg(grades: list) -> str:
|
||||
if len(grades) < 1:
|
||||
return ""
|
||||
if len(grades) < 1:
|
||||
return ""
|
||||
|
||||
sum_ = 0
|
||||
for i in grades:
|
||||
sum_ += int(i)
|
||||
avg = round(sum_ / len(grades), 2)
|
||||
sum_ = 0
|
||||
for i in grades:
|
||||
sum_ += int(i)
|
||||
avg = round(sum_ / len(grades), 2)
|
||||
|
||||
avg = str(avg)
|
||||
if len(avg) == 3:
|
||||
avg += "0"
|
||||
avg = str(avg)
|
||||
if len(avg) == 3:
|
||||
avg += "0"
|
||||
|
||||
return avg
|
||||
return avg
|
||||
"""
|
||||
|
||||
def get_grades(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")
|
||||
|
||||
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)
|
||||
avg = rows[i].find("td", class_="VHCelkPrumer").text
|
||||
temp_dict["AVG"] = avg
|
||||
|
||||
return grades
|
||||
except AttributeError:
|
||||
global not_login
|
||||
grades.append(temp_dict)
|
||||
|
||||
not_login = 1
|
||||
grades = fetch_locally()
|
||||
return grades
|
||||
return grades
|
||||
except AttributeError:
|
||||
global not_login
|
||||
|
||||
def show_grades():
|
||||
if nw.is_connected() == True:
|
||||
grades = get_grades("/SOL/App/Hodnoceni/KZH001_HodnVypisStud.aspx")
|
||||
grades_to_file(grades)
|
||||
else:
|
||||
grades = grades_from_file()
|
||||
not_login = 1
|
||||
grades = fetch_locally()
|
||||
return grades
|
||||
|
||||
whitespace = ""
|
||||
max_len_of_subject = 0
|
||||
subjects = [grades[j]["SUBJECT"] for j in range(len(grades))]
|
||||
for i in subjects:
|
||||
if len(i) > max_len_of_subject:
|
||||
max_len_of_subject = len(i)
|
||||
max_len_of_subject += 1
|
||||
def show_grades(local=False):
|
||||
if local == False:
|
||||
if nw.is_connected() == True:
|
||||
grades = get_grades("/SOL/App/Hodnoceni/KZH001_HodnVypisStud.aspx")
|
||||
grades_to_file(grades)
|
||||
else:
|
||||
grades = grades_from_file()
|
||||
else:
|
||||
grades = grades_from_file()
|
||||
|
||||
print("")
|
||||
whitespace = ""
|
||||
max_len_of_subject = 0
|
||||
subjects = [grades[j]["SUBJECT"] for j in range(len(grades))]
|
||||
for i in subjects:
|
||||
if len(i) > max_len_of_subject:
|
||||
max_len_of_subject = len(i)
|
||||
max_len_of_subject += 1
|
||||
|
||||
print("--------")
|
||||
print(" Známky ")
|
||||
print("--------\n")
|
||||
print("")
|
||||
|
||||
if grades == []:
|
||||
print("N/A\n")
|
||||
import os
|
||||
print("--------")
|
||||
print(" Známky ")
|
||||
print("--------\n")
|
||||
|
||||
if os.path.exists(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv"):
|
||||
os.remove(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv")
|
||||
return
|
||||
if grades == []:
|
||||
print("N/A\n")
|
||||
import os
|
||||
|
||||
for i in range(len(grades)):
|
||||
if grades[i]["GRADES"] != []:
|
||||
whitespace = " " * (max_len_of_subject - len(grades[i]["SUBJECT"]))
|
||||
print(grades[i]["SUBJECT"] + whitespace + "|", end=" ")
|
||||
print(get_avg(grades[i]["GRADES"]), "|", end=" ")
|
||||
print("".join([grades[i]["GRADES"][j]+" " for j in range(len(grades[i]["GRADES"]))]), end=" ")
|
||||
print("")
|
||||
if os.path.exists(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv"):
|
||||
os.remove(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv")
|
||||
return
|
||||
|
||||
for i in range(len(grades)):
|
||||
if grades[i]["GRADES"] != []:
|
||||
whitespace = " " * (max_len_of_subject - len(grades[i]["SUBJECT"]))
|
||||
print(grades[i]["SUBJECT"] + whitespace + "|", end=" ")
|
||||
print(grades[i]["AVG"], "|", end=" ")
|
||||
print("".join([grades[i]["GRADES"][j]+" " for j in range(len(grades[i]["GRADES"]))]), end=" ")
|
||||
print("")
|
||||
|
||||
def grades_to_file(grades=None): # !!! make sure the format of the grades list is saved correctly !!!
|
||||
import csv
|
||||
if grades is None:
|
||||
try:
|
||||
grades = get_grades("/SOL/App/Hodnoceni/KZH001_HodnVypisStud.aspx")
|
||||
except Exception:
|
||||
print("An error occured, you probably can't access the internet right now")
|
||||
return
|
||||
import csv
|
||||
if grades is None:
|
||||
try:
|
||||
grades = get_grades("/SOL/App/Hodnoceni/KZH001_HodnVypisStud.aspx")
|
||||
except Exception:
|
||||
print("An error occured, you probably can't access the internet right now")
|
||||
return
|
||||
|
||||
data = []
|
||||
data = []
|
||||
|
||||
with open(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv", mode="w", newline="") as f:
|
||||
for i in range(len(grades)):
|
||||
temp = {}
|
||||
temp["SUBJECT"] = grades[i]["SUBJECT"]
|
||||
temp_grades = []
|
||||
for j in range(len(grades[i]["GRADES"])):
|
||||
temp_grades.append(grades[i]["GRADES"][j])
|
||||
temp["GRADES"] = temp_grades
|
||||
data.append(temp)
|
||||
with open(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv", mode="w", newline="") as f:
|
||||
for i in range(len(grades)):
|
||||
temp = {}
|
||||
temp["SUBJECT"] = grades[i]["SUBJECT"]
|
||||
temp["AVG"] = grades[i]["AVG"]
|
||||
temp_grades = []
|
||||
for j in range(len(grades[i]["GRADES"])):
|
||||
temp_grades.append(grades[i]["GRADES"][j])
|
||||
temp["GRADES"] = temp_grades
|
||||
data.append(temp)
|
||||
|
||||
writer = csv.writer(f)
|
||||
for row in data:
|
||||
_row = []
|
||||
_row.append(row["SUBJECT"])
|
||||
for i in row["GRADES"]:
|
||||
_row.append(i)
|
||||
writer.writerow(_row)
|
||||
writer = csv.writer(f)
|
||||
for row in data:
|
||||
_row = []
|
||||
_row.append(row["SUBJECT"])
|
||||
_row.append(row["AVG"])
|
||||
for i in row["GRADES"]:
|
||||
_row.append(i)
|
||||
writer.writerow(_row)
|
||||
|
||||
def grades_from_file() -> list:
|
||||
import csv
|
||||
grades = []
|
||||
import csv
|
||||
grades = []
|
||||
|
||||
try:
|
||||
with open(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv", mode="r") as f:
|
||||
reader = csv.reader(f)
|
||||
rows = []
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
try:
|
||||
with open(f"{os.environ['HOME']}/.local/lib/solendata/grades.csv", mode="r") as f:
|
||||
reader = csv.reader(f)
|
||||
rows = []
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
|
||||
for row in range(len(rows)):
|
||||
temp = {}
|
||||
for row in range(len(rows)):
|
||||
temp = {}
|
||||
|
||||
temp["SUBJECT"] = rows[row][0]
|
||||
|
||||
temp_lst = []
|
||||
for i in range(1, len(rows[row])):
|
||||
temp_lst.append(rows[row][i])
|
||||
temp["GRADES"] = temp_lst
|
||||
temp["SUBJECT"] = rows[row][0]
|
||||
temp["AVG"] = rows[row][1]
|
||||
|
||||
temp_lst = []
|
||||
for i in range(2, len(rows[row])):
|
||||
temp_lst.append(rows[row][i])
|
||||
temp["GRADES"] = temp_lst
|
||||
|
||||
grades.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No grades.csv file found\n")
|
||||
grades.append(temp)
|
||||
except FileNotFoundError:
|
||||
print("No grades.csv file found\n")
|
||||
|
||||
return grades
|
||||
return grades
|
||||
|
||||
@@ -41,7 +41,7 @@ def _get_creds_hash(user: str, pwd: str) -> str:
|
||||
return creds
|
||||
|
||||
def login(user: str, pwd: str) -> bool:
|
||||
if is_connected() == True:
|
||||
if is_connected():
|
||||
url: str = "https://aplikace.skolaonline.cz/SOL/Prihlaseni.aspx"
|
||||
data = {
|
||||
"__EVENTTARGET": "dnn$ctr994$SOLLogin$btnODeslat",
|
||||
@@ -83,7 +83,7 @@ def is_connected() -> bool:
|
||||
s = socket.create_connection((host, 80), 2)
|
||||
s.close()
|
||||
return True
|
||||
except Exception:
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ def get_schedule(url: str):
|
||||
temp.append(" - ")
|
||||
wheres = temp
|
||||
|
||||
for j in range(len(cells)):
|
||||
for j in range(len(cells)):
|
||||
if cells[j].get("colspan") is not None:
|
||||
if int(cells[j].get("colspan")) == 2:
|
||||
try:
|
||||
@@ -177,12 +177,15 @@ def get_whitespace(key: str, idx=0) -> int:
|
||||
|
||||
return max_len
|
||||
|
||||
def show_schedule():
|
||||
# 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("/SOL/App/Spolecne/KZZ010_RychlyPrehled.aspx")
|
||||
schedule_to_file(schedule)
|
||||
def show_schedule(local=False):
|
||||
if local == False:
|
||||
# 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("/SOL/App/Spolecne/KZZ010_RychlyPrehled.aspx")
|
||||
schedule_to_file(schedule)
|
||||
else:
|
||||
schedule = schedule_from_file()
|
||||
else:
|
||||
schedule = schedule_from_file()
|
||||
|
||||
|
||||
@@ -200,12 +200,15 @@ def get_whitespace(key: str, idx=0) -> int:
|
||||
|
||||
return max_len
|
||||
|
||||
def show_schedule():
|
||||
# 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("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
|
||||
schedule_to_file(schedule)
|
||||
def show_schedule(local=False):
|
||||
if local == False:
|
||||
# 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("/SOL/App/Kalendar/KZK001_KalendarTyden.aspx")
|
||||
schedule_to_file(schedule)
|
||||
else:
|
||||
schedule = schedule_from_file()
|
||||
else:
|
||||
schedule = schedule_from_file()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user