⬆️ Bump pydantic to 2.0

This commit is contained in:
xtaodada 2023-07-01 10:11:55 +08:00
parent e6be7a0e61
commit f21a6d6ae3
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 7 additions and 5 deletions

5
add.py
View File

@ -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")

View File

@ -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__':

View File

@ -1,4 +1,4 @@
pydantic
pydantic==2.0
httpx
beautifulsoup4
lxml