PriceForecast/原油八大维度预测任务.py

48 lines
1.4 KiB
Python
Raw Normal View History

2025-03-13 10:33:47 +08:00
# 这是原油日度,周度,月度的预测,脚本
# 遍历时间跳过周六日每日7点开始预测
import datetime
import subprocess
import time
def run_predictions(target_date):
"""执行三个预测脚本"""
scripts = [
# "main_yuanyou.py",
2025-03-14 14:11:20 +08:00
# "main_yuanyou_zhoudu.py",
2025-03-13 10:33:47 +08:00
"main_yuanyou_yuedu.py"
]
# 依次执行每个脚本
for script in scripts:
command = ["python", script]
subprocess.run(command, check=True)
2025-03-13 10:33:47 +08:00
def is_weekday(date):
"""判断是否为工作日(周一到周五)"""
return date.weekday() < 5 # 0-4 为周一到周五
if __name__ == "__main__":
# start_date = datetime.date(2025, 3, 13)
# 开始时间取当前时间
start_date = datetime.date.today()
2025-03-13 10:33:47 +08:00
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(
2025-03-14 14:11:20 +08:00
current_date, datetime.time(13, 15))
2025-03-13 10:33:47 +08:00
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)