From d605de9de42d31dc0a7bc69611f629aec7e10416 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sat, 15 Apr 2023 09:38:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=8F=8A=E5=85=AC=E5=91=8A=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/announcement.json | 1 + res/scripts/publish_announcement.py | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 res/announcement.json create mode 100644 res/scripts/publish_announcement.py diff --git a/res/announcement.json b/res/announcement.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/res/announcement.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/res/scripts/publish_announcement.py b/res/scripts/publish_announcement.py new file mode 100644 index 00000000..812e83d9 --- /dev/null +++ b/res/scripts/publish_announcement.py @@ -0,0 +1,32 @@ +# 输出工作路径 +import os +print("工作路径: " + os.getcwd()) +announcement = input("请输入公告内容: ") + +import json + +# 读取现有的公告文件 res/announcement.json +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()) + +# 获取最后一个公告的id +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 +} + +announcement_json.append(announcement) + +# 将公告写入公告文件 +with open("res/announcement.json", "w", encoding="utf-8") as f: + json.dump(announcement_json, f, indent=4, ensure_ascii=False)