PriceForecast/原油八大维度预测任务.py
2025-03-13 10:33:47 +08:00

46 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 这是原油日度,周度,月度的预测,脚本
# 遍历时间跳过周六日每日7点开始预测
import datetime
import subprocess
import time
def run_predictions(target_date):
"""执行三个预测脚本"""
scripts = [
"main_yuanyou.py",
"main_yuanyou_zhoudu.py",
"main_yuanyou_yuedu.py"
]
# 合并命令为单个进程执行
command = ["python"]
command.extend(scripts)
subprocess.run(command, check=True)
def is_weekday(date):
"""判断是否为工作日(周一到周五)"""
return date.weekday() < 5 # 0-4 为周一到周五
if __name__ == "__main__":
start_date = datetime.date(2025, 3, 13)
end_date = datetime.date(2100, 12, 31)
current_date = start_date
while current_date <= end_date:
if is_weekday(current_date):
# 等待到目标日期的7点
target_time = datetime.datetime.combine(
current_date, datetime.time(9, 40))
while datetime.datetime.now() < target_time:
time.sleep(60) # 每分钟检查一次
print(f"等待到 {target_time} 开始执行任务")
print(f"开始执行 {current_date} 的预测任务")
run_predictions(current_date)
current_date += datetime.timedelta(days=1)