diff --git a/src/impl/hebece/src/api.py b/src/impl/hebece/src/api.py index 772cdce..718f19e 100644 --- a/src/impl/hebece/src/api.py +++ b/src/impl/hebece/src/api.py @@ -16,6 +16,17 @@ def getDebugInfo(data): message = status.get("Message") return code, message +def makeRequest(url): + digest, canonical_url, signature = get_signature_values(fingerprint, private_key, body=None, full_url=url, timestamp=datetime.now()) + + headers = makeHeader(signature, canonical_url) + + response = requests.get(url, headers=headers) + content = response.text + + dinfo = getDebugInfo(content) + return content, dinfo + def APILogin(login, password): url = "https://eduvulcan.pl/" @@ -111,82 +122,31 @@ def JWTLogin(token, debug=False): def HEBELogin(tenant, debug=False): url = f"https://lekcjaplus.vulcan.net.pl/{tenant}{HEBE}?mode=2&lastSyncDate=1970-01-01%2001%3A00%3A00" - - digest, canonical_url, signature = get_signature_values(fingerprint, private_key, body=None, full_url=url, timestamp=datetime.now()) - - headers = makeHeader(signature, canonical_url) - - response = requests.get(url, headers=headers) - content = response.text - - if debug: - dinfo = getDebugInfo(content) - return content, dinfo - - return content + content, dinfo = makeRequest(url) + return content, dinfo def getLuckyNumber(tenant, schoolid, pupilid, constituentid, debug=False): timestamp = datetime.now() date = timestamp.strftime("%Y-%m-%d") url = f"https://lekcjaplus.vulcan.net.pl/{tenant}/{schoolid}{LUCKY}?pupilId={pupilid}&constituentId={constituentid}&day={date}" - - digest, canonical_url, signature = get_signature_values(fingerprint, private_key, body=None, full_url=url, timestamp=datetime.now()) - headers = makeHeader(signature, canonical_url) - - response = requests.get(url, headers=headers) - content = response.text - - if debug: - dinfo = getDebugInfo(content) - return content, dinfo - - return content + content, dinfo = makeRequest(url) + return content, dinfo def getGrades(tenant, schoolid, pupilid, unitid, periodid, debug=False): url = f"https://lekcjaplus.vulcan.net.pl/{tenant}/{schoolid}/api/mobile/grade/byPupil?unitId={unitid}&pupilId={pupilid}&periodId={periodid}&lastSyncDate=1970-01-01%2001%3A00%3A00&lastId=-2147483648&pageSize=500" - digest, canonical_url, signature = get_signature_values(fingerprint, private_key, body=None, full_url=url, timestamp=datetime.now()) - - headers = makeHeader(signature, canonical_url) - - response = requests.get(url, headers=headers) - content = response.text - - - if debug: - dinfo = getDebugInfo(content) - return content, dinfo - - return content + content, dinfo = makeRequest(url) + return content, dinfo def getTimetable(tenant, schoolid, pupilid, start_date, end_date, debug=False): url = f"https://lekcjaplus.vulcan.net.pl/{tenant}/{schoolid}/api/mobile/schedule/withchanges/byPupil?pupilId={pupilid}&dateFrom={start_date}&dateTo={end_date}&lastId=-2147483648&pageSize=500&lastSyncDate=1970-01-01%2001%3A00%3A00" - digest, canonical_url, signature = get_signature_values(fingerprint, private_key, body=None, full_url=url, timestamp=datetime.now()) - - headers = makeHeader(signature, canonical_url) - - response = requests.get(url, headers=headers) - content = response.text - - if debug: - dinfo = getDebugInfo(content) - return content, dinfo - - return content + content, dinfo = makeRequest(url) + return content, dinfo def getExams(tenant, schoolid, pupilid, start_date, end_date, debug=False): url = f"https://lekcjaplus.vulcan.net.pl/{tenant}/{schoolid}/api/mobile/exam/byPupil?pupilId={pupilid}&dateFrom={start_date}&dateTo={end_date}&lastId=-2147483648&pageSize=500&lastSyncDate=1970-01-01%2001%3A00%3A00" - digest, canonical_url, signature = get_signature_values(fingerprint, private_key, body=None, full_url=url, timestamp=datetime.now()) - - headers = makeHeader(signature, canonical_url) - response = requests.get(url, headers=headers) - content = response.text - - if debug: - dinfo = getDebugInfo(content) - return content, dinfo - - return content + content, dinfo = makeRequest(url) + return content, dinfo diff --git a/src/impl/hebece/src/parser.py b/src/impl/hebece/src/parser.py new file mode 100644 index 0000000..18cc204 --- /dev/null +++ b/src/impl/hebece/src/parser.py @@ -0,0 +1,37 @@ +import requests +import json +import uuid +import hashlib +import sqlite3 +import os +import base64 +from impl.hebece.src.signer import * +from impl.hebece.src.utils import * +from impl.hebece.src.api import * +from datetime import datetime, timedelta +from bs4 import BeautifulSoup + +def getUserInfo(tenant): + content, dinfo = HEBELogin(tenant) + + data = json.loads(content) + envelope = data.get("Envelope", [])[0] + + pupil = envelope.get("Pupil", {}) + unit = envelope.get("Unit", {}) + links = envelope.get("Links", {}) + ConstituentUnit = envelope.get("ConstituentUnit", {}) + periods = envelope.get("Periods", []) + + + Name = pupil.get("FirstName", {}) + SecondName = pupil.get("SecondName", {}) + Surname = pupil.get("Surname", {}) + Class = envelope.get("ClassDisplay", {}) + PupilID = pupil.get("Id", {}) + SchoolID = links.get("Symbol", {}) + ConstituentID = ConstituentUnit.get("Id", {}) + UnitID = unit.get("Id", {}) + PeriodID = next((period.get('Id') for period in periods if period.get('Current')), None) + + return Name, SecondName, Surname, Class, PupilID, SchoolID, ConstituentID, UnitID, PeriodID \ No newline at end of file diff --git a/src/impl/hebece/src/sdkmain.py b/src/impl/hebece/src/sdkmain.py deleted file mode 100644 index 6671d87..0000000 --- a/src/impl/hebece/src/sdkmain.py +++ /dev/null @@ -1,94 +0,0 @@ -import requests -import json -import uuid -import hashlib -import sqlite3 -import os -import base64 -from impl.hebece.src.signer import * -from impl.hebece.src.utils import * -from impl.hebece.src.api import * -from datetime import datetime, timedelta -from bs4 import BeautifulSoup - -if __name__ == '__main__': - debug = True -else: - debug = False - -def getDebugInfo(data): - data = json.loads(data) - status = data.get("Status", {}) - code = status.get("Code") - message = status.get("Message") - return code, message - -def getUserInfo(tenant): - content = HEBELogin(tenant) - - data = json.loads(content) - envelope = data.get("Envelope", [])[0] - - pupil = envelope.get("Pupil", {}) - unit = envelope.get("Unit", {}) - links = envelope.get("Links", {}) - ConstituentUnit = envelope.get("ConstituentUnit", {}) - periods = envelope.get("Periods", []) - - - Name = pupil.get("FirstName", {}) - SecondName = pupil.get("SecondName", {}) - Surname = pupil.get("Surname", {}) - Class = envelope.get("ClassDisplay", {}) - PupilID = pupil.get("Id", {}) - SchoolID = links.get("Symbol", {}) - ConstituentID = ConstituentUnit.get("Id", {}) - UnitID = unit.get("Id", {}) - PeriodID = next((period.get('Id') for period in periods if period.get('Current')), None) - - return Name, SecondName, Surname, Class, PupilID, SchoolID, ConstituentID, UnitID, PeriodID - -if __name__ == '__main__': - today = datetime.today().strftime('%d-%m-%y') - start_date, end_date = get_current_week() - - token = APILogin(login, password) - tenant = get_tenant_from_jwt(token) - content, dinfoJWT = JWTLogin(token, debug=debug) - content, dinfoHEBE = HEBELogin(tenant, debug=debug) - - Name, SecondName, Surname, Class, PupilID, SchoolID, ConstituentID, UnitID, PeriodID = getUserInfo(tenant) - print(Name, Surname, Class, PupilID, SchoolID, ConstituentID) - - LuckyNumber, LuckyNumberDay, dinfoLUCK = getLuckyNumber(tenant=tenant, schoolid=SchoolID, pupilid=PupilID, constituentid=ConstituentID, debug=debug) - print(f"Lucky number: {LuckyNumber}") - - content, dinfoGRADE = getGrades(tenant=tenant, schoolid=SchoolID, pupilid=PupilID, unitid=UnitID, periodid=PeriodID, debug=debug) - - response, dinfoTIME = getTimetable(tenant=tenant, schoolid=SchoolID, pupilid=PupilID, start_date=start_date, end_date=end_date, debug=debug) - - - r = getTimetableForDay(day=today) - print(f"\nLessons for {today}:") - - if r == []: - print("No lessons for today") - else: - for lesson in r: - print(*lesson) - - content, dinfoEXAM = getExams(tenant=tenant, schoolid=SchoolID, pupilid=PupilID, start_date=start_date, end_date=end_date, debug=debug) - - ImportExamsToSQLite(content) - print("Exams imported to SQLite database") - - exams = getExamsForWeek(start_date, end_date) - for exam in exams: - print(*exam) - - print(f"\nJWT Status: {dinfoJWT[0]} {dinfoJWT[1]}") - print(f"HEBE Status: {dinfoHEBE[0]} {dinfoHEBE[1]}") - print(f"Lucky Number Status: {dinfoLUCK[0]} {dinfoLUCK[1]}") - print(f"Grades Status: {dinfoGRADE[0]} {dinfoGRADE[1]}") - print(f"Timetable Status: {dinfoTIME[0]} {dinfoTIME[1]}") - print(f"Exams Status: {dinfoEXAM[0]} {dinfoEXAM[1]}") \ No newline at end of file diff --git a/src/test.py b/src/test.py index f99a213..8599afb 100644 --- a/src/test.py +++ b/src/test.py @@ -1,5 +1,5 @@ from impl.hebece.src.api import * -from impl.hebece.src.sdkmain import * +from impl.hebece.src.parser import * from impl.hebece.src.utils import * from impl.hebece.src.signer import *