diff --git a/.github/workflows/license.yaml b/.github/workflows/license.yaml index f35d7e3..8e96037 100644 --- a/.github/workflows/license.yaml +++ b/.github/workflows/license.yaml @@ -1,4 +1,4 @@ -name: Update LICENSE Year +name: LICENSE on: schedule: @@ -13,7 +13,7 @@ runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Update LICENSE Year diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ab8cbf..b050110 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,21 +17,8 @@ hooks: - id: cmake-format - id: cmake-lint - - repo: https://github.com/cmhughes/latexindent.pl - rev: V3.23.1 - hooks: - - id: latexindent - files: .(tex|sty|cls|bib)$ - types: - - text - args: - - --overwriteIfDifferent - - --silent - - --cruft=/tmp - - --modifylinebreaks - - --GCString - repo: https://github.com/commitizen-tools/commitizen - rev: 3.9.0 + rev: 3.10.0 hooks: - id: commitizen - repo: https://github.com/pre-commit/mirrors-clang-format @@ -139,3 +126,18 @@ - id: go-vet-repo-mod - id: go-fmt - id: go-fmt-repo + - repo: local + hooks: + - id: latexindent + name: Pretty LaTeX + entry: latexindent + language: system + files: .(tex|sty|cls|bib)$ + types: + - text + args: + - --overwriteIfDifferent + - --silent + - --cruft=/tmp + - --modifylinebreaks + - --GCString diff --git a/poetry.lock b/poetry.lock index 4c8887d..c22c000 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,14 +1,14 @@ -# This file is automatically @generated by Poetry 1.6.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. [[package]] name = "altgraph" -version = "0.17.3" +version = "0.17.4" description = "Python graph (network) package" optional = false python-versions = "*" files = [ - {file = "altgraph-0.17.3-py2.py3-none-any.whl", hash = "sha256:c8ac1ca6772207179ed8003ce7687757c04b0b71536f81e2ac5755c6226458fe"}, - {file = "altgraph-0.17.3.tar.gz", hash = "sha256:ad33358114df7c9416cdb8fa1eaa5852166c505118717021c6a8c7c7abbd03dd"}, + {file = "altgraph-0.17.4-py2.py3-none-any.whl", hash = "sha256:642743b4750de17e655e6711601b077bc6598dbfa3ba5fa2b2a35ce12b508dff"}, + {file = "altgraph-0.17.4.tar.gz", hash = "sha256:1b5afbb98f6c4dcadb2e2ae6ab9fa994bbb8c1d75f4fa96d340f9437ae454406"}, ] [[package]] @@ -299,13 +299,13 @@ [[package]] name = "macholib" -version = "1.16.2" +version = "1.16.3" description = "Mach-O header analysis and editing" optional = false python-versions = "*" files = [ - {file = "macholib-1.16.2-py2.py3-none-any.whl", hash = "sha256:44c40f2cd7d6726af8fa6fe22549178d3a4dfecc35a9cd15ea916d9c83a688e0"}, - {file = "macholib-1.16.2.tar.gz", hash = "sha256:557bbfa1bb255c20e9abafe7ed6cd8046b48d9525db2f9b77d3122a63a2a8bf8"}, + {file = "macholib-1.16.3-py2.py3-none-any.whl", hash = "sha256:0e315d7583d38b8c77e815b1ecbdbf504a8258d8b3e17b61165c6feb60d18f2c"}, + {file = "macholib-1.16.3.tar.gz", hash = "sha256:07ae9e15e8e4cd9a788013d81f5908b3609aa76f9b1421bae9c4d7606ec86a30"}, ] [package.dependencies] @@ -359,12 +359,12 @@ [[package]] name = "nuitka" -version = "1.8.1" +version = "1.8.2" description = "Python compiler with full language support and CPython compatibility" optional = false python-versions = "*" files = [ - {file = "Nuitka-1.8.1.tar.gz", hash = "sha256:62c4cbcca101f8259497997571ccfa243a2f7a2700526239f5a0c19b1cda09f1"}, + {file = "Nuitka-1.8.2.tar.gz", hash = "sha256:720db0cae384d44bf713c200cf062b8e0e927b948783f92e5c667d662879c92c"}, ] [package.dependencies] @@ -613,13 +613,13 @@ [[package]] name = "urllib3" -version = "2.0.4" +version = "2.0.5" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false python-versions = ">=3.7" files = [ - {file = "urllib3-2.0.4-py3-none-any.whl", hash = "sha256:de7df1803967d2c2a98e4b11bb7d6bd9210474c46e8a0401514e3a42a75ebde4"}, - {file = "urllib3-2.0.4.tar.gz", hash = "sha256:8d22f86aae8ef5e410d4f539fde9ce6b2113a001bb4d189e0aed70642d602b11"}, + {file = "urllib3-2.0.5-py3-none-any.whl", hash = "sha256:ef16afa8ba34a1f989db38e1dbbe0c302e4289a47856990d0682e374563ce35e"}, + {file = "urllib3-2.0.5.tar.gz", hash = "sha256:13abf37382ea2ce6fb744d4dad67838eec857c9f4f57009891805e0b5e123594"}, ] [package.extras] diff --git a/requirements.txt b/requirements.txt index 51094ba..a0431fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,4 +12,4 @@ soupsieve==2.5 ; python_version >= "3.11" and python_version < "3.12" typer==0.9.0 ; python_version >= "3.11" and python_version < "3.12" typing-extensions==4.8.0 ; python_version >= "3.11" and python_version < "3.12" -urllib3==2.0.4 ; python_version >= "3.11" and python_version < "3.12" +urllib3==2.0.5 ; python_version >= "3.11" and python_version < "3.12" diff --git a/template b/template index 86cd0e0..ff2f337 160000 --- a/template +++ b/template @@ -1 +1 @@ -Subproject commit 86cd0e04d5f27f55511e331f02d3d829ef865233 +Subproject commit ff2f337063accbb2431bdb627844af100f804839 diff --git a/thu_learn_downloader/__main__.py b/thu_learn_downloader/__main__.py index 2621511..a9c32c8 100644 --- a/thu_learn_downloader/__main__.py +++ b/thu_learn_downloader/__main__.py @@ -62,28 +62,21 @@ with Live(progress_group) as live: with downloader.pool: - try: - helper.login(username=username, password=password) - except: - live.console.log( - f"Login as {username} FAILED", - style="bold bright_red", - ) - else: - live.console.log( - SUCCESS_PREFIX, - f"Login as {username} SUCCESS", - style="bold bright_green", - ) - sync.sync_all( - helper=helper, - downloader=downloader, - config=config, - console=live.console, - overall_progress=overall_progress, - semesters_task_id=semesters_task_id, - courses_task_id=courses_task_id, - ) + helper.login(username=username, password=password) + live.console.log( + SUCCESS_PREFIX, + f"Login as {username} SUCCESS", + style="bold bright_green", + ) + sync.sync_all( + helper=helper, + downloader=downloader, + config=config, + console=live.console, + overall_progress=overall_progress, + semesters_task_id=semesters_task_id, + courses_task_id=courses_task_id, + ) if __name__ == "__main__": diff --git a/thu_learn_downloader/parser.py b/thu_learn_downloader/parser.py index cff0f2e..38ef93f 100644 --- a/thu_learn_downloader/parser.py +++ b/thu_learn_downloader/parser.py @@ -60,12 +60,12 @@ student_homework_id=raw["xszyid"], # 学生作业 ID number=int(raw["wz"]), # title=str(html.unescape(raw["bt"])).strip(), # 标题 - starts_time=utils.from_timestamp(raw.get("kssj")), # 开始时间 - deadline=utils.from_timestamp(raw.get("jzsj")), # 截止时间 - submit_time=utils.from_timestamp(raw.get("scsj")), # 上传时间 + starts_time=utils.parse_time(raw.get("kssj")), # 开始时间 + deadline=utils.parse_time(raw.get("jzsj")), # 截止时间 + submit_time=utils.parse_time(raw.get("scsj")), # 上传时间 grade=raw.get("cj", ""), # 成绩 grader_name=raw.get("jsm", ""), # 教师名 - grade_time=utils.from_timestamp(raw.get("pysj")), # 批阅时间 + grade_time=utils.parse_time(raw.get("pysj")), # 批阅时间 grade_content=raw.get("pynr", ""), # 批阅内容 **utils.dataclass_as_dict_shallow(status), **utils.dataclass_as_dict_shallow(detail), diff --git a/thu_learn_downloader/utils.py b/thu_learn_downloader/utils.py index 7d5c0c6..093d46a 100644 --- a/thu_learn_downloader/utils.py +++ b/thu_learn_downloader/utils.py @@ -27,10 +27,14 @@ return f"{course_name} > {hw_title} > {filename}" -def from_timestamp(t: Optional[float]) -> Optional[datetime]: +def parse_time(t: Optional[float | str]) -> Optional[datetime]: if not t: return None - return datetime.fromtimestamp(t / 1000.0) + match t: + case float(): + return datetime.fromtimestamp(t / 1000.0) + case str(): + return datetime.strptime(t, "%Y-%m-%d %H:%M") def dataclass_as_dict_shallow(obj: Any) -> dict[str, Any]: