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