From 7f20952fb4df4105394c65fe18f4eacbdccca7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 17 Sep 2021 13:02:54 +0200 Subject: [PATCH] add open.py file to easily open course-related stuff --- scripts/links.py | 6 +++++- scripts/open.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 scripts/open.py diff --git a/scripts/links.py b/scripts/links.py index 7389e82..efbeebf 100644 --- a/scripts/links.py +++ b/scripts/links.py @@ -1,14 +1,18 @@ import subprocess +from typing import Dict, List class Links: def __init__(self, course): self.course = course # A course - self.info = course.info['links'] + self.info: Dict = course.info['links'] def open(self, key: str): self.open_link_in_browser(self.info[key]) + def available(self) -> List[str]: + return [key for key in self.info.keys() if self.info[key] != ''] + @staticmethod def open_link_in_browser(url): result = subprocess.run( diff --git a/scripts/open.py b/scripts/open.py new file mode 100644 index 0000000..a84b9c9 --- /dev/null +++ b/scripts/open.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +from courses import Courses +import sys + + +def open_spec(specification: str): + current = Courses().current + + switcher = { + 'full': current.notes.open_full, + 'master': current.notes.open_master + } + + if specification in switcher.keys(): + return switcher[specification]() + + link_type = { + 'webpage': 'webpage', + 'w': 'webpage', + 'url': 'webpage', + 'u': 'webpage', + 'ecampus': 'ecampus', + 'e': 'ecampus', + 'sciebo': 'sciebo', + 's': 'sciebo', + 'basis': 'basis', + 'b': 'basis', + 'github': 'github', + 'g': 'github' + } + return current.links.open(link_type[specification]) + + +if __name__ == "__main__": + for arg in sys.argv[1:]: + open_spec(arg)