Fix and extend example config

This commit is contained in:
Joscha 2020-04-24 18:41:22 +00:00
parent 1aaa6e7ab5
commit 13c5a29ff0

View File

@ -1,33 +1,120 @@
""" import argparse
A small sample config for PFERD. from pathlib import Path, PurePath
"""
from pathlib import Path
from PFERD import Pferd, enable_logging import PFERD
from PFERD.ilias.download_strategies import (download_everything, from PFERD.transform import (attempt, glob, keep, move, move_dir, optionally,
download_modified_or_new) re_move)
tf_ss_2020_numerik = attempt(
re_move(r"Übungsblätter/(\d+)\. Übungsblatt/.*", "Blätter/Blatt_{1:0>2}.pdf"),
keep,
)
tf_ss_2020_db = attempt(
move_dir("Begrüßungsvideo/", "Vorlesung/Videos/"),
move_dir("Vorlesungsmaterial/Vorlesungsvideos/", "Vorlesung/Videos/"),
move_dir("Vorlesungsmaterial/", "Vorlesung/"),
keep,
)
tf_ss_2020_rechnernetze = attempt(
re_move(r"Vorlesungsmaterial/.*/(.+?)\.mp4", "Vorlesung/Videos/{1}.mp4"),
move_dir("Vorlesungsmaterial/", "Vorlesung/"),
keep,
)
tf_ss_2020_sicherheit = attempt(
move_dir("Vorlesungsvideos/", "Vorlesung/Videos/"),
move_dir("Übungsvideos/", "Übung/Videos/"),
re_move(r"VL(.*)\.pdf", "Vorlesung/{1}.pdf"),
re_move(r"Übungsblatt (\d+)\.pdf", "Blätter/Blatt_{1:0>2}.pdf"),
move("Chiffrat.txt", "Blätter/Blatt_01_Chiffrat.txt"),
keep,
)
tf_ss_2020_pg = attempt(
move_dir("Vorlesungsaufzeichnungen/", "Vorlesung/Videos/"),
move_dir("Vorlesungsmaterial/", "Vorlesung/"),
re_move(r"Übungen/uebungsblatt(\d+).pdf", "Blätter/Blatt_{1:0>2}.pdf"),
keep,
)
def df_ss_2020_or1(path: PurePath) -> bool:
if glob("Tutorien/")(path): return True
if glob("Tutorien/Tutorium 10, dienstags 15:45 Uhr/")(path): return True
if glob("Tutorien/*")(path): return False
return True
tf_ss_2020_or1 = attempt(
move_dir("Vorlesung/Unbeschriebene Folien/", "Vorlesung/Folien/"),
move_dir("Video zur Organisation/", "Vorlesung/Videos/"),
keep,
)
def main() -> None: def main() -> None:
enable_logging() parser = argparse.ArgumentParser()
pferd = Pferd(Path(__file__).parent) parser.add_argument("--test-run", action="store_true")
parser.add_argument("synchronizers", nargs="*")
args = parser.parse_args()
# Synchronize "databases" and only download files with a more recent timestamp than PFERD.enable_logging()
# the local copy, if any exists. pferd = PFERD.Pferd(Path(__file__).parent, test_run=args.test_run)
pferd.ilias_kit(
Path("DB"),
"1101554",
cookies=Path("ilias_cookies.txt"),
download_strategy=download_modified_or_new
)
# Synchronize "databases" and redownload every file (default). if not args.synchronizers or "numerik" in args.synchronizers:
pferd.ilias_kit( pferd.ilias_kit(
Path("DB"), target="Numerik",
"1101554", course_id="1083036",
cookies=Path("ilias_cookies.txt"), transform=tf_ss_2020_numerik,
download_strategy=download_everything cookies="ilias_cookies.txt",
) )
if not args.synchronizers or "db" in args.synchronizers:
pferd.ilias_kit(
target="DB",
course_id="1101554",
transform=tf_ss_2020_db,
cookies="ilias_cookies.txt",
)
if not args.synchronizers or "rechnernetze" in args.synchronizers:
pferd.ilias_kit(
target="Rechnernetze",
course_id="1099996",
transform=tf_ss_2020_rechnernetze,
cookies="ilias_cookies.txt",
)
if not args.synchronizers or "sicherheit" in args.synchronizers:
pferd.ilias_kit(
target="Sicherheit",
course_id="1101980",
transform=tf_ss_2020_sicherheit,
cookies="ilias_cookies.txt",
)
if not args.synchronizers or "pg" in args.synchronizers:
pferd.ilias_kit(
target="PG",
course_id="1106095",
transform=tf_ss_2020_pg,
cookies="ilias_cookies.txt",
)
if not args.synchronizers or "or1" in args.synchronizers:
pferd.ilias_kit(
target="OR1",
course_id="1105941",
dir_filter=df_ss_2020_or1,
transform=tf_ss_2020_or1,
cookies="ilias_cookies.txt",
)
if __name__ == "__main__": if __name__ == "__main__":