From f21a6d6ae300d2b8a956831853363efa52d3be10 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 1 Jul 2023 10:11:55 +0800 Subject: [PATCH] :arrow_up: Bump pydantic to 2.0 --- add.py | 5 +++-- main.py | 5 +++-- requirements.txt | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/add.py b/add.py index 9b8a142..7076bf2 100644 --- a/add.py +++ b/add.py @@ -1,3 +1,4 @@ +import json from pathlib import Path from pytz import timezone from sys import argv @@ -41,7 +42,7 @@ if __name__ == '__main__': raise IndexError code = add(argv[2], argv[3], argv[4:]) with open(custom_path, "r", encoding="utf-8") as f: - custom: CodeList = CodeList.parse_raw(f.read()) + custom: CodeList = CodeList.model_validate_json(f.read()) if add_type == "main": main_codes = [i.code for i in custom.main] if code.code in main_codes: @@ -55,7 +56,7 @@ if __name__ == '__main__': custom.main.sort(key=lambda x: x.expire, reverse=True) custom.over.sort(key=lambda x: x.expire, reverse=True) with open(custom_path, "w", encoding="utf-8") as f: - f.write(custom.json(indent=4, ensure_ascii=False)) + f.write(json.dumps(custom.model_dump(), indent=4, ensure_ascii=False)) except IndexError: print("Usage: python add.py [main/over] [code] [expire] [rewards...]") print("Example: python add.py main code 2023-11-1 星琼:1 信用点:1000") diff --git a/main.py b/main.py index 3b402cd..b8e7c74 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import json from typing import List from models.code import CodeList, Code @@ -23,10 +24,10 @@ def merge_code(over: List[Code], custom: CodeList) -> CodeList: def main(): over = get_code() with open(custom_path, "r", encoding="utf-8") as f: - custom = CodeList.parse_raw(f.read()) + custom = CodeList.model_validate_json(f.read()) custom = merge_code(over, custom) with open(code_path, "w", encoding="utf-8") as f: - f.write(custom.json(indent=4, ensure_ascii=False)) + f.write(json.dumps(custom.model_dump(), indent=4, ensure_ascii=False)) if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt index 027342d..25cae7c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pydantic +pydantic==2.0 httpx beautifulsoup4 lxml