用于条件调度的Python Scheduler

问题描述 投票:0回答:1

谁能帮我写一个python调度程序,它可以根据一定的条件,比如调用API数据库的重试次数和优先级排序等,来完成工作(比如从API数据库中获取数据)。

python mongodb algorithm api scheduler
1个回答
0
投票

我是Python的初学者,但是我的问题是 附表包 是非常直接的。使用 pip install schedule 只需为你的工作定义一个函数并设置时间表。你的代码可能看起来像这样。

import requests
import schedule

def job(url, filename=''):
   with requests.get(url) as req:
       with open(filename, 'wb') as f:
            for chunk in req.iter_content(chunk_size=1024000):
                if chunk:
                    f.write(chunk)
job(url)
schedule.every().hour.do(job, url=url)
while True:
       schedule.run_pending()
       time.sleep(1)
© www.soinside.com 2019 - 2024. All rights reserved.