mirror of
https://github.com/PaiGramTeam/Gift-Code-Web.git
synced 2024-11-21 06:47:19 +00:00
⬆️ Bump pydantic to 2.0
This commit is contained in:
parent
e6be7a0e61
commit
f21a6d6ae3
5
add.py
5
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")
|
||||
|
5
main.py
5
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__':
|
||||
|
@ -1,4 +1,4 @@
|
||||
pydantic
|
||||
pydantic==2.0
|
||||
httpx
|
||||
beautifulsoup4
|
||||
lxml
|
||||
|
Loading…
Reference in New Issue
Block a user