From 9b528a91a2c839a34becabf1d4ad4c19553bdbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 17 Sep 2021 12:42:08 +0200 Subject: [PATCH] add Links class to courses to manage course links --- scripts/courses.py | 8 ++++++++ scripts/links.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 scripts/links.py diff --git a/scripts/courses.py b/scripts/courses.py index ba68b15..5c9ff63 100644 --- a/scripts/courses.py +++ b/scripts/courses.py @@ -7,6 +7,7 @@ from typing import List from config import ROOT, CURRENT_COURSE_ROOT, CURRENT_COURSE_SYMLINK, CURRENT_COURSE_WATCH_FILE, COURSE_IGNORE_FILE, \ COURSE_INFO_FILE_NAME, FALLBACK_COURSE_INFO_FILE from notes import Notes +from links import Links from utils import merge_dictionaries @@ -30,6 +31,13 @@ class Course: fallback_file = {} self.info = merge_dictionaries(self.info, fallback_file) self._notes = None + self._links = None + + @property + def links(self) -> Links: + if not self._links: + self._links = Links(self) + return self._links @property def notes(self) -> Notes: diff --git a/scripts/links.py b/scripts/links.py new file mode 100644 index 0000000..7389e82 --- /dev/null +++ b/scripts/links.py @@ -0,0 +1,18 @@ +import subprocess + + +class Links: + def __init__(self, course): + self.course = course # A course + self.info = course.info['links'] + + def open(self, key: str): + self.open_link_in_browser(self.info[key]) + + @staticmethod + def open_link_in_browser(url): + result = subprocess.run( + ['qutebrowser', str(url)], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL + )