modify scripts
This commit is contained in:
27
src/utils/utils.py
Normal file
27
src/utils/utils.py
Normal file
@ -0,0 +1,27 @@
|
||||
import re
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
import csv
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
# 保存 JSON 数据到本地文件
|
||||
def save_json_to_file(data, file_path, file_name):
|
||||
os.makedirs(file_path, exist_ok=True)
|
||||
full_name = f"{file_path}/{file_name}"
|
||||
|
||||
with open(full_name, "w", encoding="utf-8") as file:
|
||||
json.dump(data, file, ensure_ascii=False, indent=4)
|
||||
|
||||
logging.debug(f"saved json data to: {full_name}")
|
||||
|
||||
# 判断日期字符串是否在最近七天内
|
||||
def is_within_last_week(date_str):
|
||||
try:
|
||||
file_date = datetime.strptime(date_str, '%Y-%m-%d')
|
||||
current_date = datetime.now()
|
||||
diff = current_date - file_date
|
||||
return diff.days <= 7
|
||||
except ValueError:
|
||||
return False
|
||||
Reference in New Issue
Block a user