mirror of
https://github.com/wd210010/only_for_happly.git
synced 2026-11-05 20:26:45 +08:00
Create update_date.py
This commit is contained in:
1 parent
b72327ae98
commit
6950d83526
1 file changed
+26
@@ -0,0 +1,26 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
# 获取当前日期
|
||||
current_date = datetime.now().strftime('%Y-%m-%d')
|
||||
|
||||
# 定义 JSON 文件路径
|
||||
json_file = 'date_config.json'
|
||||
|
||||
# 更新 JSON 文件
|
||||
def update_json():
|
||||
try:
|
||||
with open(json_file, 'r') as f:
|
||||
data = json.load(f)
|
||||
except FileNotFoundError:
|
||||
data = {}
|
||||
|
||||
# 更新日期字段
|
||||
data['date'] = current_date
|
||||
|
||||
# 写回更新后的内容
|
||||
with open(json_file, 'w') as f:
|
||||
json.dump(data, f, indent=4)
|
||||
|
||||
if __name__ == '__main__':
|
||||
update_json()
|
||||
Reference in new issue
Block a user