[英]How to update a Python class object every x amount of time?
I'm writing a sync script between two project-management programs. 我正在两个项目管理程序之间编写一个同步脚本。 I've created a Python class called Project and on initiation, loads data from both programs using python-requests and their respective REST APIs.
我创建了一个名为Project的Python类,并在启动时使用python-requests及其各自的REST API从这两个程序中加载数据。 However, I anticipate that the data will eventually be changed by other users using the programs.
但是,我预计其他用户最终会使用该程序更改数据。 Thus, I want to be able to update this Project object at least once every day.
因此,我希望能够至少每天更新一次此Project对象。 How do I do this?
我该怎么做呢?
import datetime as dt
class Project(object):
def __init__(self, project_key):
self.key = project_key
self.issues = {}
self.tasks = {}
self.__load_tasks() # loads all tasks into project
self.__load_issues() # loads all issues into project
self.last_updated = dt.datetime.today()
log.info('Project created on {}'.format(self.last_updated))
If you are n windows you can create a batch file that calls your python script and configure the Windows Task Scheduler to run your batch script every day at a certain hour 如果您是n个Windows,则可以创建一个调用python脚本的批处理文件,并将Windows Task Scheduler配置为每天在某个小时运行一次您的批处理脚本
your batch file should look like this 您的批处理文件应如下所示
@echo off
python path\where\your\python\script\is\your_script.py
Then create your task in Windows Task Scheduler 然后在Windows Task Scheduler中创建任务
Create a basic task and follow the guided process 创建一个基本任务并遵循指导流程
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.