48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# 这是原油日度,周度,月度的预测,脚本
|
||
# 遍历时间,跳过周六日,每日7点开始预测
|
||
|
||
import datetime
|
||
import subprocess
|
||
import time
|
||
|
||
|
||
def run_predictions(target_date):
|
||
"""执行三个预测脚本"""
|
||
scripts = [
|
||
# "main_yuanyou.py",
|
||
# "main_yuanyou_zhoudu.py",
|
||
"main_yuanyou_yuedu.py"
|
||
]
|
||
|
||
# 依次执行每个脚本
|
||
for script in scripts:
|
||
command = ["python", script]
|
||
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)
|
||
# 开始时间取当前时间
|
||
start_date = datetime.date.today()
|
||
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(13, 15))
|
||
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)
|