diff --git a/poetry.lock b/poetry.lock index f8a086d..40f70eb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -113,11 +113,11 @@ [[package]] name = "gitdb" -version = "4.0.9" +version = "4.0.10" description = "Git Object Database" category = "dev" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" [package.dependencies] smmap = ">=3.0.1,<6" @@ -382,7 +382,7 @@ [[package]] name = "pymdown-extensions" -version = "9.8" +version = "9.9" description = "Extension pack for Python Markdown." category = "dev" optional = false @@ -497,7 +497,7 @@ [[package]] name = "setuptools" -version = "65.6.0" +version = "65.6.3" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "dev" optional = false @@ -542,11 +542,11 @@ [[package]] name = "urllib3" -version = "1.26.12" +version = "1.26.13" description = "HTTP library with thread-safe connection pooling, file post, and more." category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" [package.extras] brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] @@ -613,8 +613,8 @@ {file = "ghp_import-2.1.0-py3-none-any.whl", hash = "sha256:8337dd7b50877f163d4c0289bc1f1c7f127550241988d568c1db512c4324a619"}, ] gitdb = [ - {file = "gitdb-4.0.9-py3-none-any.whl", hash = "sha256:8033ad4e853066ba6ca92050b9df2f89301b8fc8bf7e9324d412a63f8bf1a8fd"}, - {file = "gitdb-4.0.9.tar.gz", hash = "sha256:bac2fd45c0a1c9cf619e63a90d62bdc63892ef92387424b855792a6cabe789aa"}, + {file = "gitdb-4.0.10-py3-none-any.whl", hash = "sha256:c286cf298426064079ed96a9e4a9d39e7f3e9bf15ba60701e95f5492f28415c7"}, + {file = "gitdb-4.0.10.tar.gz", hash = "sha256:6eb990b69df4e15bad899ea868dc46572c3f75339735663b81de79b06f17eb9a"}, ] GitPython = [ {file = "GitPython-3.1.29-py3-none-any.whl", hash = "sha256:41eea0deec2deea139b459ac03656f0dd28fc4a3387240ec1d3c259a2c47850f"}, @@ -815,8 +815,8 @@ {file = "pyinstaller_hooks_contrib-2022.13-py2.py3-none-any.whl", hash = "sha256:91ecb30db757a8db8b6661d91d5df99e0998245f05f5cfaade0550922c7030a3"}, ] pymdown-extensions = [ - {file = "pymdown_extensions-9.8-py3-none-any.whl", hash = "sha256:8e62688a8b1128acd42fa823f3d429d22f4284b5e6dd4d3cd56721559a5a211b"}, - {file = "pymdown_extensions-9.8.tar.gz", hash = "sha256:1bd4a173095ef8c433b831af1f3cb13c10883be0c100ae613560668e594651f7"}, + {file = "pymdown_extensions-9.9-py3-none-any.whl", hash = "sha256:ac698c15265680db5eb13cd4342abfcde2079ac01e5486028f47a1b41547b859"}, + {file = "pymdown_extensions-9.9.tar.gz", hash = "sha256:0f8fb7b74a37a61cc34e90b2c91865458b713ec774894ffad64353a5fce85cfc"}, ] pyparsing = [ {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, @@ -893,8 +893,8 @@ {file = "rich-12.6.0.tar.gz", hash = "sha256:ba3a3775974105c221d31141f2c116f4fd65c5ceb0698657a11e9f295ec93fd0"}, ] setuptools = [ - {file = "setuptools-65.6.0-py3-none-any.whl", hash = "sha256:6211d2f5eddad8757bd0484923ca7c0a6302ebc4ab32ea5e94357176e0ca0840"}, - {file = "setuptools-65.6.0.tar.gz", hash = "sha256:d1eebf881c6114e51df1664bc2c9133d022f78d12d5f4f665b9191f084e2862d"}, + {file = "setuptools-65.6.3-py3-none-any.whl", hash = "sha256:57f6f22bde4e042978bcd50176fdb381d7c21a9efa4041202288d3737a0c6a54"}, + {file = "setuptools-65.6.3.tar.gz", hash = "sha256:a7620757bf984b58deaf32fc8a4577a9bbc0850cf92c20e1ce41c38c19e5fb75"}, ] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, @@ -913,8 +913,8 @@ {file = "text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8"}, ] urllib3 = [ - {file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"}, - {file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"}, + {file = "urllib3-1.26.13-py2.py3-none-any.whl", hash = "sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc"}, + {file = "urllib3-1.26.13.tar.gz", hash = "sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"}, ] watchdog = [ {file = "watchdog-2.1.9-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:a735a990a1095f75ca4f36ea2ef2752c99e6ee997c46b0de507ba40a09bf7330"}, diff --git a/requirements.txt b/requirements.txt index d76d50f..76c413a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,4 @@ rich==12.6.0 ; python_version >= "3.10" and python_version < "3.12" soupsieve==2.3.2.post1 ; python_version >= "3.10" and python_version < "3.12" text-unidecode==1.3 ; python_version >= "3.10" and python_version < "3.12" -urllib3==1.26.12 ; python_version >= "3.10" and python_version < "3.12" +urllib3==1.26.13 ; python_version >= "3.10" and python_version < "3.12" diff --git a/scripts/install.sh b/scripts/install.sh index e177d0e..d8b9302 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -35,7 +35,7 @@ function copy() { mkdir --parents "$(realpath --canonicalize-missing ${2}/..)" cp --force --recursive "${1}" "${2}" - success "${1} -> ${2}" + success "Copy: ${1} -> ${2}" } cd "$(git rev-parse --show-toplevel || echo .)" diff --git a/thu_learn_downloader/downloader.py b/thu_learn_downloader/downloader.py index 936612d..dd2d2c3 100644 --- a/thu_learn_downloader/downloader.py +++ b/thu_learn_downloader/downloader.py @@ -18,7 +18,7 @@ console: rich.console.Console = rich.console.Console(), progress: rich.progress.Progress = rich.progress.Progress(), task_id: rich.progress.TaskID = rich.progress.TaskID(0), -) -> None: +) -> bool: res = (session or requests).get(url=url, stream=True) raw_size = int(res.headers.get("Content-Length", 0)) or raw_size if os.path.exists(file): @@ -27,7 +27,7 @@ mtime = os.path.getmtime(filename=file) mtime = datetime.datetime.fromtimestamp(mtime) if mtime >= upload_time: - return + return False os.makedirs(name=os.path.dirname(file), exist_ok=True) progress.reset(task_id=task_id, total=raw_size) with open(file=file, mode="wb") as fp: @@ -40,6 +40,7 @@ if upload_time: mtime = int(upload_time.timestamp()) os.utime(path=file, times=(mtime, mtime)) + return True def download( @@ -60,7 +61,7 @@ f"Retry {i}: {progress.tasks[task_id].description}", style="bold bright_blue", ) - download_once( + ret = download_once( url=url, file=file, raw_size=raw_size, @@ -76,10 +77,16 @@ style="bold bright_red", ) else: - console.log( - f"Download Success: {progress.tasks[task_id].description}", - style="bold bright_green", - ) + if ret: + console.log( + f"Download Success: {progress.tasks[task_id].description}", + style="bold bright_green", + ) + else: + console.log( + f"Download Skipped: {progress.tasks[task_id].description}", + style="dim", + ) progress.update(task_id=task_id, visible=False) return diff --git a/thu_learn_downloader/sync.py b/thu_learn_downloader/sync.py index 5756732..b499b8c 100644 --- a/thu_learn_downloader/sync.py +++ b/thu_learn_downloader/sync.py @@ -190,7 +190,7 @@ with open(file=file, mode="w") as fp: fp.write(readme.dump_work(work)) if shutil.which(cmd="prettier"): - os.system(f"prettier --write {file}") + os.system(f"prettier --write {file} > /dev/null") def sync_work_attachment( @@ -214,6 +214,13 @@ for p in ["attach", "ans", "submit", "comment"]: title = title.removeprefix(p + "-") title = attachment_type + "-" + title + upload_time = None + if attachment_type == "submit": + upload_time = work.submit_time + elif attachment_type == "comment": + upload_time = work.grade_time + else: + upload_time = None downloader.schedule_download( url=attachment.download_url, file=os.path.join( @@ -223,6 +230,7 @@ utils.slugify(work.title), utils.slugify(title), ), + upload_time=upload_time, session=helper, console=console, description=f"[bold bright_blue]{course.name} > {title}",