zermelo api for python
Project description
zermelo api v:2024.03.08.19.21.22
install
pip install zermeloforpython
source code
import requests,re,datetime
from .schedule import schedule
from .scheduleitem import scheduleitem
class zermelo:
def __init__(self, school, username,password=None, teacher=False, version=3,debug=False):
self.school = school
self.username = username
self.password = password
self.teacher = teacher
self.version = version
self.debug = debug
self.base_url = f"https://{self.school}.zportal.nl/api/v{self.version}/"
self.session = requests.Session()
self.login()
def get_date(self):
now = datetime.datetime.now()
return (now.year,now.isocalendar()[1],int((datetime.datetime.fromtimestamp(now.timestamp()) - datetime.datetime.utcfromtimestamp(now.timestamp())).total_seconds() / 3600))
def login(self):
token = re.search("code=[0-z]*",self.session.post(f"{self.base_url}oauth?tenant={self.school}&client_id=OAuthPage&redirect_uri=/main/&scope=&state=4E252A&response_type=code&username={self.username}&password={self.password}",allow_redirects=False).headers["location"]).group()[5::]
self.access_token = self.session.post(f"{self.base_url}oauth/token?code={token}&client_id=ZermeloPortal&client_secret=42&grant_type=authorization_code&rememberMe=False").json()["access_token"]
self.session.headers.update({"Authorization": f"Bearer {self.access_token}"})
def get_raw_scedule(self,year=0,week=0,datemode="absolute"):
tyear, tweek,_ = self.get_date()
if datemode == "absolute":
if year == 0:
year = tyear
if week == 0:
week = tweek
elif datemode == "relative":
year += tyear
week += tweek
if week > 52:
year += week % 52
week = 52
if week < 1:
year -= week % 52
week = 1
return self.session.get(f"{self.base_url}liveschedule?{'teacher' if (self.teacher) else 'student'}={self.username}&week={year}{week:0>2}").json()
def get_schedule(self,week=0,year=0,datemode="absolute"):
return schedule(self.get_raw_scedule(week=week,year=year,datemode=datemode),self)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for zermelo_for_python-2024.3.8.19.21.22-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a912ab5738978e7dc32dd0cdb5a187efd1d1e29c57d0de965c83c2712940dd09 |
|
MD5 | efeb179e00001e0c60c2fbd5a4a07e4f |
|
BLAKE2b-256 | 5637b45deae166b42e94565c34ace60d1890546f03de2eac2ff2123ae6e3981e |