Skip to content

Instantly share code, notes, and snippets.

@developerfromjokela
Last active July 25, 2023 17:50
Show Gist options
  • Save developerfromjokela/dfc0ac42c2382a15c455a7d7b654bf4e to your computer and use it in GitHub Desktop.
Save developerfromjokela/dfc0ac42c2382a15c455a7d7b654bf4e to your computer and use it in GitHub Desktop.
Wilma opintopiste laskuri
import requests
# Wilma2SID= cookie value here
SESSION = ""
# Your Wilma Base URL
BASEURL = "https://example.inschool.fi/!0249962/"
# Schedule ID as ENV if you know already, otherwise select using CLI
SCHEDULE = os.environ.get("SCHEDULE", '')
def get_own_trays():
return requests.get(BASEURL + f"api/v1/me/trays", cookies={"Wilma2SID": SESSION}).json()[
"payload"]
def get_trays():
return requests.get(BASEURL + f"api/v1/schedules/{SCHEDULE}/trays", cookies={"Wilma2SID": SESSION}).json()[
"payload"]
def get_tray_units(tray_id):
return \
requests.get(BASEURL + f"api/v1/schedules/{SCHEDULE}/trays/{tray_id}/units",
cookies={"Wilma2SID": SESSION}).json()[
"payload"]
def get_course_info(course_id):
return requests.get(BASEURL + f"api/v1/courses/{course_id}", cookies={"Wilma2SID": SESSION}).json()["payload"]
trays = get_own_trays()
if SCHEDULE is None or len(SCHEDULE) < 1:
schedule_list = {}
for itm in trays:
if 'schedule' in itm and itm['schedule']['identifier'] not in schedule_list:
schedule_list[itm['schedule']['identifier']] = itm['schedule']
for idx, schedule in enumerate(list(schedule_list.values())):
print(f"[{idx}] {schedule['caption']}")
sch_idx = int(input("Select schedule to calculate:"))
SCHEDULE = list(schedule_list.values())[sch_idx]['identifier']
trays = get_trays()
op_total = 0
for tray in trays:
print()
print("|TRAY| " + tray["caption"])
tray_units = get_tray_units(tray["id"])
count = 0
for unit in tray_units:
print()
print(" [PALKKI] " + unit["sortIdentifier"])
tmp_points = 0
for module in unit.get("modules", []):
if module["isSelected"]:
course_info = get_course_info(module["moduleBaseId"])
print(" ->", course_info['abbreviation'], course_info['caption'])
if "scope" in course_info and "credits" in course_info["scope"]:
op_total += course_info["scope"]["credits"]
tmp_points += course_info["scope"]["credits"]
count += 1
print(" TOTAL", count, "POINTS", tmp_points)
print()
print("TOTAL POINTS:", op_total)
import requests
# Wilma2SID= cookie value here
SESSION = ""
# Your Wilma Base URL
BASEURL = "https://example.inschool.fi/!0249962/"
def get_course_info(course_id):
return requests.get(BASEURL + f"api/v1/courses/{course_id}", cookies={"Wilma2SID": SESSION}).json()["payload"]
def get_all_evaluations():
return requests.get(BASEURL + "api/v1/me/evaluations", cookies={"Wilma2SID": SESSION}).json()["payload"]
evaluations = get_all_evaluations()
op_total = 0
for item in evaluations:
if "executions" not in item or len(item["executions"]) < 1 or item["executions"][0].get("isFailed"):
pass
course_info = get_course_info(item["id"])
if "scope" in course_info and "credits" in course_info["scope"]:
op_total += course_info["scope"]["credits"]
print(" ->", item.get("caption"))
print(" ->", course_info.get('scope', course_info))
print("TOTAL POINTS:", op_total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment