style: introduce ruff as linter and formatter (#1356)

* style: remove necessary imports

* style: fix F841

* style: fix F401

* style: fix F811

* style: fix E402

* style: fix E721

* style: fix E722

* style: fix E722

* style: fix F541

* style: ruff format

* style: all passed

* style: add ruff in deps

* style: more ignores in ruff.toml

* style: add pre-commit
This commit is contained in:
Junyan Qin (Chin)
2025-04-29 17:24:07 +08:00
committed by GitHub
parent 09e70d70e9
commit 209f16af76
240 changed files with 5307 additions and 4689 deletions

View File

@@ -1,32 +1,32 @@
# 输出工作路径
import os
print("工作路径: " + os.getcwd())
announcement = input("请输入公告内容: ")
import time
import json
print('工作路径: ' + os.getcwd())
announcement = input('请输入公告内容: ')
# 读取现有的公告文件 res/announcement.json
with open("res/announcement.json", "r", encoding="utf-8") as f:
with open('res/announcement.json', 'r', encoding='utf-8') as f:
announcement_json = json.load(f)
# 将公告内容写入公告文件
# 当前自然时间
import time
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
# 获取最后一个公告的id
last_id = announcement_json[-1]["id"] if len(announcement_json) > 0 else -1
last_id = announcement_json[-1]['id'] if len(announcement_json) > 0 else -1
announcement = {
"id": last_id + 1,
"time": now,
"timestamp": int(time.time()),
"content": announcement
'id': last_id + 1,
'time': now,
'timestamp': int(time.time()),
'content': announcement,
}
announcement_json.append(announcement)
# 将公告写入公告文件
with open("res/announcement.json", "w", encoding="utf-8") as f:
with open('res/announcement.json', 'w', encoding='utf-8') as f:
json.dump(announcement_json, f, indent=4, ensure_ascii=False)