Add support for other years in TGI downloader

This commit is contained in:
I-Al-Istannen 2019-10-15 15:37:52 +02:00
parent 458cc1c6d6
commit 1973c931bd

View File

@ -16,14 +16,15 @@ logger = logging.getLogger(__name__)
pretty = PrettyLogger(logger) pretty = PrettyLogger(logger)
class TGI: class TGI:
CRAWL_URL = "https://i11www.iti.kit.edu/teaching/winter2019/tgi/index" CRAWL_URL = "https://i11www.iti.kit.edu/teaching/{year}/tgi/index"
BASE_URL = "https://i11www.iti.kit.edu" BASE_URL = "https://i11www.iti.kit.edu"
LINK_RE = re.compile(r"^/_media/teaching/.*?/(tgi-\d+-\d+-)([^/]*\.pdf)$") LINK_RE = re.compile(r"^/_media/teaching/.*?/(tgi-\d+-\d+-)([^/]*\.pdf)$")
def __init__(self, base_path): def __init__(self, base_path, year="winter2019"):
self.base_path = base_path self.base_path = base_path
self._session = requests.Session() self._session = requests.Session()
self.year = year
def synchronize(self, to_dir, transform=lambda x: x): def synchronize(self, to_dir, transform=lambda x: x):
pretty.starting_synchronizer(to_dir, "TGI") pretty.starting_synchronizer(to_dir, "TGI")
@ -40,7 +41,7 @@ class TGI:
orga.clean_temp_dir() orga.clean_temp_dir()
def _crawl(self): def _crawl(self):
url = self.CRAWL_URL url = self.CRAWL_URL.replace("{year}", self.year)
r = self._session.get(url) r = self._session.get(url)
text = r.text text = r.text