diff --git a/.gitignore b/.gitignore index 6fe11b1..e407f6c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ -/learn +# hydra outputs +outputs +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -22,7 +27,6 @@ sdist/ var/ wheels/ -pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg @@ -52,6 +56,7 @@ *.py,cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo @@ -74,6 +79,7 @@ docs/_build/ # PyBuilder +.pybuilder/ target/ # Jupyter Notebook @@ -84,7 +90,9 @@ ipython_config.py # pyenv -.python-version +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. @@ -93,7 +101,22 @@ # install all needed dependencies. #Pipfile.lock -# PEP 582; used by e.g. github.com/David-OConnor/pyflow +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ # Celery stuff @@ -129,3 +152,18 @@ # Pyre type checker .pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# End of https://www.toptal.com/developers/gitignore/api/python diff --git a/identity.yaml b/identity.yaml new file mode 100644 index 0000000..cc675f1 --- /dev/null +++ b/identity.yaml @@ -0,0 +1,9 @@ +username: "*******" +password: "**************" +prefix: "/home/liblaf/Onedrive/thu-course/" +file_size_limit: null +sync_docs: true +sync_work: true +sync_submit: true +semesters: + - "2022-2023-1" diff --git a/main.py b/main.py index c0df3a2..2c97002 100644 --- a/main.py +++ b/main.py @@ -1,70 +1,23 @@ -import argparse - +import hydra +import omegaconf import tqdm from downloader import Downloader -parser = argparse.ArgumentParser( - add_help="Automatically download files from THU Web Learning." -) -parser.add_argument("--username", required=True) -parser.add_argument("--password", required=True) -parser.add_argument( - "--semesters", - nargs="+", - default=None, - required=False, - help="semesters to be synced. If you want to sync all semesters, do not pass this argument", -) -parser.add_argument( - "--prefix", - default="thu-learn", - required=False, - help='location to save downloaded files, default to "learn/"', -) -parser.add_argument( - "--file_size_limit", - default=None, - type=float, - required=False, - help="(unit: MB) files exceed limit will not be downloaded", -) -parser.add_argument( - "--no_sync_docs", - action="store_true", - default=False, - required=False, - help="pass this argument to skip syncing files", -) -parser.add_argument( - "--no_sync_work", - action="store_true", - default=False, - required=False, - help="pass this argument to skip syncing homework", -) -parser.add_argument( - "--no_sync_submit", - action="store_true", - default=False, - required=False, - help="pass this argument to skip syncing your submission & grade and everything personal", -) - - -def main(args: argparse.Namespace): +@hydra.main(config_path=".", config_name="identity.yaml", version_base="1.2") +def main(cfg: omegaconf.DictConfig): downloader = Downloader( - username=args.username, - password=args.password, - prefix=args.prefix, - file_size_limit=args.file_size_limit, - sync_docs=(not args.no_sync_docs), - sync_work=(not args.no_sync_work), - sync_submit=(not args.no_sync_submit), + username=cfg["username"], + password=cfg["password"], + prefix=cfg["prefix"], + file_size_limit=cfg["file_size_limit"], + sync_docs=cfg["sync_docs"], + sync_work=cfg["sync_work"], + sync_submit=cfg["sync_submit"], ) semester_id_list: list[str] = downloader.helper.get_semester_id_list() - semesters: list[str] = args.semesters if args.semesters else semester_id_list + semesters: list[str] = cfg["semesters"] if cfg["semesters"] else semester_id_list for semester in tqdm.tqdm( iterable=semesters, desc="semesters", @@ -79,5 +32,4 @@ if __name__ == "__main__": - args = parser.parse_args() - main(args) + main() diff --git a/requirements.txt b/requirements.txt index cf6ad45..7bd260f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ beautifulsoup4~=4.11.1 +hydra-core~=1.2.0 +omegaconf~=2.2.3 requests~=2.28.1 tqdm~=4.64.1 python-slugify~=6.1.2