Skip to content

Instantly share code, notes, and snippets.

@Birdi7
Created May 25, 2022 18:08
Show Gist options
  • Save Birdi7/35c33ef8c7a5bbbb2a9bf13074d21dd1 to your computer and use it in GitHub Desktop.
Save Birdi7/35c33ef8c7a5bbbb2a9bf13074d21dd1 to your computer and use it in GitHub Desktop.
# берет хтмл из grades на my.university.innopolis.ru,
# и считает гпа по формуле (grades * credits)/credits.
# положить файлик рядом с main.py под именем gpa.html
# КАЧАЙ html из https://my.university.innopolis.ru/profile/personal-form/index?tab=validations
from bs4 import BeautifulSoup
with open("gpa.html", "r") as f:
html_doc = f.read()
soup = BeautifulSoup(html_doc, "html.parser")
tbody = soup.find("tbody")
TRANSLATE = {"A": 4, "B": 3, "C": 2, "D": 1, "P": 4}
results = []
done = set()
for t in tbody.find_all("tr"):
all_tds = t.find_all("td")
subject_name = all_tds[1]
if subject_name in done:
continue
done.add(subject_name)
credits = all_tds[2]
grade = t.find("b")
results.append({"credits": int(credits.text), "grade": TRANSLATE[grade.text]})
from pprint import pprint
pprint(results)
print(sum(entry["grade"] * entry["credits"] for entry in results) / sum(entry["credits"] for entry in results))
print(len(results))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment