diff options
author | Nao Pross <np@0hm.ch> | 2022-11-16 23:45:48 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2022-11-16 23:45:48 +0100 |
commit | 0c08cd07377ab2dff76913f144c233311de638c8 (patch) | |
tree | e68951ea115794015e21261a8c8742283d1cacb2 /muddle | |
parent | Fix regression from upgrade to PyQt6 (diff) | |
download | Muddle-0c08cd07377ab2dff76913f144c233311de638c8.tar.gz Muddle-0c08cd07377ab2dff76913f144c233311de638c8.zip |
Move ApiHelper and add comment for schema in muddle.moodle
Diffstat (limited to '')
-rw-r--r-- | muddle/moodle.py | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/muddle/moodle.py b/muddle/moodle.py index 489f50a..870de8a 100644 --- a/muddle/moodle.py +++ b/muddle/moodle.py @@ -74,7 +74,28 @@ class MoodleInstance: yield Course._fromdict(c) +class ApiHelper: + def __init__(self, api): + self.api = api + + def get_userid(self): + req = self.api.core_webservice_get_site_info() + if req: + return req.json()["userid"] + else: + return None + + def get_file(self, url, local_path): + with requests.post(url, data={"token": self.api._token}, stream=True) as r: + r.raise_for_status() + with open(local_path, "wb") as f: + for chunk in r.iter_content(chunk_size=8192): + if chunk: + f.write(chunk) + + # A bare minimum impl of Moodle SCHEMA +# This is an experiment and not currently in use! # Beware that lots of parameters have been omitted class SchemaObj: @@ -158,23 +179,3 @@ class Folder(SchemaObj): @dataclasses.dataclass class ExternalLink(SchemaObj): pass - - -class ApiHelper: - def __init__(self, api): - self.api = api - - def get_userid(self): - req = self.api.core_webservice_get_site_info() - if req: - return req.json()["userid"] - else: - return None - - def get_file(self, url, local_path): - with requests.post(url, data={"token": self.api._token}, stream=True) as r: - r.raise_for_status() - with open(local_path, "wb") as f: - for chunk in r.iter_content(chunk_size=8192): - if chunk: - f.write(chunk) |