37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
import re
|
|
import os
|
|
import json
|
|
import time
|
|
import csv
|
|
import logging
|
|
from datetime import datetime
|
|
import config
|
|
|
|
tbl_stock = 'reports_stock'
|
|
tbl_new_stock = 'reports_newstrock'
|
|
tbl_strategy = 'reports_strategy'
|
|
tbl_macresearch = 'reports_macresearch'
|
|
tbl_industry = 'reports_industry'
|
|
|
|
json_data_dir = f'{config.global_host_data_dir}/em_reports/json_data'
|
|
|
|
# 保存 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
|