crypto_quant/auto_update_market_data.py

36 lines
1.2 KiB
Python
Raw Permalink Normal View History

2025-08-20 08:40:33 +00:00
import schedule
import time
2025-09-16 06:31:15 +00:00
from core.utils import get_current_date_time
2025-08-20 08:40:33 +00:00
import core.logger as logging
import subprocess
import os
2025-09-16 06:31:15 +00:00
import sys
2025-08-20 08:40:33 +00:00
logger = logging.logger
# 定义要执行的任务
def run_script():
start_time = time.time()
2025-09-16 06:31:15 +00:00
logger.info(f"Executing script at: {get_current_date_time()}")
2025-10-20 10:37:41 +00:00
output_file = r'./output/auto_update_market_data.txt'
2025-08-20 08:40:33 +00:00
with open(output_file, 'a') as f:
2025-09-16 06:31:15 +00:00
f.write(f"Task ran at {get_current_date_time()}\n")
python_path = sys.executable
current_dir = os.getcwd()
if current_dir.endswith('crypto_quant'):
script_path = r'./huge_volume_main.py'
elif current_dir.endswith(r'python_projects'):
script_path = f'{current_dir}/crypto_quant/huge_volume_main.py'
else:
script_path = f'{current_dir}/huge_volume_main.py'
2025-08-20 08:40:33 +00:00
subprocess.run([python_path, script_path])
end_time = time.time()
logger.info(f"Script execution time: {end_time - start_time} seconds")
# 设置每小时运行一次
interval = 60 * 60
schedule.every(interval).seconds.do(run_script)
# 保持程序运行并检查调度
logger.info("Scheduler started. Press Ctrl+C to stop.")
while True:
schedule.run_pending()
time.sleep(1)