mirror of
https://github.com/PaiGramTeam/Gift-Code-Web.git
synced 2024-11-21 22:58:18 +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 pathlib import Path
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
from sys import argv
|
from sys import argv
|
||||||
@ -41,7 +42,7 @@ if __name__ == '__main__':
|
|||||||
raise IndexError
|
raise IndexError
|
||||||
code = add(argv[2], argv[3], argv[4:])
|
code = add(argv[2], argv[3], argv[4:])
|
||||||
with open(custom_path, "r", encoding="utf-8") as f:
|
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":
|
if add_type == "main":
|
||||||
main_codes = [i.code for i in custom.main]
|
main_codes = [i.code for i in custom.main]
|
||||||
if code.code in main_codes:
|
if code.code in main_codes:
|
||||||
@ -55,7 +56,7 @@ if __name__ == '__main__':
|
|||||||
custom.main.sort(key=lambda x: x.expire, reverse=True)
|
custom.main.sort(key=lambda x: x.expire, reverse=True)
|
||||||
custom.over.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:
|
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:
|
except IndexError:
|
||||||
print("Usage: python add.py [main/over] [code] [expire] [rewards...]")
|
print("Usage: python add.py [main/over] [code] [expire] [rewards...]")
|
||||||
print("Example: python add.py main code 2023-11-1 星琼:1 信用点:1000")
|
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 typing import List
|
||||||
|
|
||||||
from models.code import CodeList, Code
|
from models.code import CodeList, Code
|
||||||
@ -23,10 +24,10 @@ def merge_code(over: List[Code], custom: CodeList) -> CodeList:
|
|||||||
def main():
|
def main():
|
||||||
over = get_code()
|
over = get_code()
|
||||||
with open(custom_path, "r", encoding="utf-8") as f:
|
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)
|
custom = merge_code(over, custom)
|
||||||
with open(code_path, "w", encoding="utf-8") as f:
|
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__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pydantic
|
pydantic==2.0
|
||||||
httpx
|
httpx
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
lxml
|
lxml
|
||||||
|
Loading…
Reference in New Issue
Block a user