diff options
author | Nao Pross <np@0hm.ch> | 2020-10-23 00:47:12 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2020-10-23 00:47:12 +0200 |
commit | 56e669fa6f37112f928919198e7f6cec7c3c0f3c (patch) | |
tree | 330324ec4cf4458d9a451745494b0ed18125d199 | |
parent | Fix config path (expand) error (diff) | |
download | Muddle-56e669fa6f37112f928919198e7f6cec7c3c0f3c.tar.gz Muddle-56e669fa6f37112f928919198e7f6cec7c3c0f3c.zip |
Make PEP8 happy
Diffstat (limited to '')
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | gui.py | 4 | ||||
-rw-r--r-- | moodle.py | 13 | ||||
-rw-r--r-- | muddle.py | 11 |
4 files changed, 27 insertions, 10 deletions
@@ -19,7 +19,14 @@ muddle $ ./muddle --gui The code is a bit garbage, as I hacked it toghether in one morning, though I've tried to clean it up a bit. -## Compilation / Release +### Coding style + +Use PEP8 except where Qt bindings are used (`gui.py`). To check use +``` +$ pep8 --show-source --ignore=E501 moodle.py muddle.py <more files...> +``` + +### Compilation / Release To create an executable you need PyInstaller, you can get it with ``` $ pip3 install pyinstaller @@ -111,7 +111,7 @@ class MoodleFetcher(QThread): sectionsReq = self.api.core_course_get_contents(courseid = str(course["id"])) if not sectionsReq: - return + return [] sections = sectionsReq.json() return sections @@ -150,7 +150,7 @@ class MoodleTreeView(QTreeWidget): @pyqtSlot(QTreeWidgetItem, int) def onItemDoubleClicked(self, item, col): log.debug(f"double clicked on item with type {str(item.metadata.type)}") - if item.type == MoodleItem.Type.FILE: + if item.metadata.type == MoodleItem.Type.FILE: # TODO: download in a temp folder and open pass @@ -7,15 +7,22 @@ log = logging.getLogger("muddle.moodle") # # magic moodle api wrapper # + + def request_token(url, user, password): token_url = f"{url}/login/token.php" - data = { "username": user, "password": password, "service": "moodle_mobile_app" } + data = { + "username": user, + "password": password, + "service": "moodle_mobile_app" + } log.debug(f"requesting token with POST to {api_url} with DATA {data}") return requests.post(token_url, data=data) + def api_call(url, token, function, **kwargs): api_url = f"{url}/webservice/rest/server.php?moodlewsrestformat=json" - data = { "wstoken": token, "wsfunction": function } + data = {"wstoken": token, "wsfunction": function} for k, v in kwargs.items(): data[str(k)] = v @@ -31,6 +38,7 @@ def api_call(url, token, function, **kwargs): log.error(f"Failed to connect for POST request:\n{str(e)}") return None + class RestApi: def __init__(self, instance_url, token): self._url = instance_url @@ -39,6 +47,7 @@ class RestApi: def __getattr__(self, key): return lambda **kwargs: api_call(self._url, self._token, str(key), **kwargs) + class ApiHelper: def __init__(self, api): self.api = api @@ -36,14 +36,15 @@ log.setLevel(logging.DEBUG) if args.verbose: cli_handler = colorlog.StreamHandler() cli_handler.setLevel(logging.DEBUG) - cli_formatter = colorlog.ColoredFormatter("%(name)-13s - %(log_color)s%(levelname)-8s%(reset)s: %(message)s", + cli_formatter = colorlog.ColoredFormatter( + "%(name)-13s - %(log_color)s%(levelname)-8s%(reset)s: %(message)s", datefmt=None, reset=True, log_colors={ - 'DEBUG': 'cyan', - 'INFO': 'green', - 'WARNING': 'yellow', - 'ERROR': 'red', + 'DEBUG': 'cyan', + 'INFO': 'green', + 'WARNING': 'yellow', + 'ERROR': 'red', 'CRITICAL': 'red,bg_white', } ) |