crypto_quant/auto_fetch_truth_social.py

37 lines
1.3 KiB
Python
Raw Permalink Normal View History

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