36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
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")
|
|
# 设置每天凌晨00:00 运行一次
|
|
schedule.every().day.at("00:00:00").do(run_script)
|
|
# schedule.every(60).seconds.do(run_script)
|
|
|
|
# 保持程序运行并检查调度
|
|
logger.info("Scheduler started. Press Ctrl+C to stop.")
|
|
while True:
|
|
schedule.run_pending()
|
|
time.sleep(1) |