Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
handle ungraded
Browse files Browse the repository at this point in the history
  • Loading branch information
mytja committed Jan 24, 2024
1 parent 6582a0d commit f238bc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
34 changes: 21 additions & 13 deletions gimsisapi/formtagparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def __str__(self):


class Grade:
def __init__(self, ocena: str, datum: str, ucitelj: str, predmet: str, tip: str, opis_ocenjevanja: str, rok: str, je_zakljucena: bool):
def __init__(self, ocena: str, datum: str, ucitelj: str, predmet: str, tip: str, opis_ocenjevanja: str, rok: str,
je_zakljucena: bool):
self.ocena = ocena
self.datum = datum
self.ucitelj = ucitelj
Expand Down Expand Up @@ -110,7 +111,6 @@ def __str__(self):
return f"Teacher({self.ime}, {self.lahko_pise}, {self.predmeti}, {self.govorilna_ura})"



def get_class(text):
soup = BeautifulSoup(text, "html.parser")
m = {0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}}
Expand Down Expand Up @@ -274,7 +274,7 @@ def get_teachers(text):


def get_grades(text):
#print(text)
# print(text)
soup = BeautifulSoup(text, "html.parser")
gradings = {"subjects": [], "average": 0.0}
table = soup.find("table", {"class": "tabelaUrnik"})
Expand All @@ -291,10 +291,10 @@ def get_grades(text):
"name": subject.find("b").text.strip(),
"average": 0.0,
"perm_average": 0.0,
0: {"average": 0.0, "perm_average": 0.0, "grades": []},
1: {"average": 0.0, "perm_average": 0.0, "grades": []},
2: {"average": 0.0, "perm_average": 0.0, "grades": []},
3: {"average": 0.0, "perm_average": 0.0, "grades": []},
0: {"average": 0.0, "perm_average": 0.0, "grades": [], "final": ""},
1: {"average": 0.0, "perm_average": 0.0, "grades": [], "final": ""},
2: {"average": 0.0, "perm_average": 0.0, "grades": [], "final": ""},
3: {"average": 0.0, "perm_average": 0.0, "grades": [], "final": ""},
"final": None,
}
total_all = 0
Expand Down Expand Up @@ -360,8 +360,14 @@ def get_grades(text):
title = grade["title"].strip().splitlines()
if koncna:
g = grade.text.strip()
if g == "C":
# neoCenjen (??????)
subject_grades[oc_obdobje]["final"] = "NOC"
continue
try:
subject_grades["final"] = int(g)
if oc_obdobje == 1:
subject_grades["final"] = int(g)
subject_grades[oc_obdobje]["final"] = int(g)
except Exception as e:
print(f"[GIMSIS FAILURE] Failure while parsing finalized grade: {e} {text}")
continue
Expand Down Expand Up @@ -395,19 +401,21 @@ def get_grades(text):
print(f"[GIMSIS FAILURE] Failure while parsing a grade: {e} {text}")
total_len = len(subject_grades[oc_obdobje]["grades"])
if total_len != 0:
subject_grades[oc_obdobje]["average"] = total/total_len
subject_grades[oc_obdobje]["average"] = total / total_len
if subject_grades[oc_obdobje]["average"] > 5:
print(f"[GIMSIS] Preseženo povprečje 5 ({subject_grades[oc_obdobje]['average']}): {text}")
if total_perm_count != 0:
subject_grades[oc_obdobje]["perm_average"] = total_perm/total_perm_count
subject_grades[oc_obdobje]["perm_average"] = total_perm / total_perm_count
if subject_grades[oc_obdobje]["average"] > 5:
print(f"[GIMSIS] Preseženo stalno povprečje 5 ({subject_grades[oc_obdobje]['perm_average']}): {text}")
print(
f"[GIMSIS] Preseženo stalno povprečje 5 ({subject_grades[oc_obdobje]['perm_average']}): {text}")
total_all += total
total_all_perm += total_perm
total_all_perm_count += total_perm_count
full_total_len = len(subject_grades[0]["grades"]) + len(subject_grades[1]["grades"]) + len(subject_grades[2]["grades"]) + len(subject_grades[3]["grades"])
full_total_len = len(subject_grades[0]["grades"]) + len(subject_grades[1]["grades"]) + len(
subject_grades[2]["grades"]) + len(subject_grades[3]["grades"])
if full_total_len != 0:
subject_grades["average"] = total_all/full_total_len
subject_grades["average"] = total_all / full_total_len

if total_all_perm_count != 0:
subject_grades["perm_average"] = total_all_perm / total_all_perm_count
Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ async def main():
# classes, days = await gimsis.fetch_timetable()
# print(classes, days)
# await gimsis.fetch_timetable("12 09 2022")
absences = await gimsis.fetch_absences("01.09.2023", to_date="11.01.2024", type=AbsenceType.by_days)
print(absences)
#absences = await gimsis.fetch_absences("01.09.2023", to_date="11.01.2024", type=AbsenceType.by_days)
#print(absences)
# gradings = await gimsis.fetch_gradings()
# print(gradings)
#grades = await gimsis.fetch_grades(year="2022")
#print(grades)
grades = await gimsis.fetch_grades(year="2022")
print(grades)
#profile = await gimsis.my_profile()
#print(profile)
#teachers = await gimsis.fetch_teachers()
Expand Down

0 comments on commit f238bc6

Please sign in to comment.