安排不在Python中工作的任务
我试图每5秒安排一项任务,我做了以下工作:安排不在Python中工作的任务,python,scheduled-tasks,feedparser,Python,Scheduled Tasks,Feedparser,我试图每5秒安排一项任务,我做了以下工作: conn = connect('mydatabase.db') c = conn.cursor() c.execute('CREATE TABLE IF NOT EXISTS RSSEntries (entry_id INTEGER PRIMARY KEY AUTOINCREMENT, title , url , date );') def checkLink(linko): c.execute("SELECT entry_id FROM
conn = connect('mydatabase.db')
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS RSSEntries (entry_id INTEGER PRIMARY KEY AUTOINCREMENT, title , url , date );')
def checkLink(linko):
c.execute("SELECT entry_id FROM RSSEntries WHERE url = ?", (linko,))
datas=c.fetchall()
if len(datas)==0:
return True
else:
return False
def storeData():
data = feedparser.parse("http://www...")
for i in range(len(data['entries'])):
if checkLink(data.entries[i].link) is True:
print "doesn't exist"
c.execute("insert into RSSEntries VALUES\
(NULL,'%s', '%s', '%s')" % (data.entries[i].title,data.entries[i].link, data.feed.updated))
else:
print "exist"
schedule.every(5).seconds.do(storeData)
conn.commit()
但是无法访问storeData
方法。。
如果我运行storeData()
而不是schedule.every(5).seconds.do(storeData)
代码工作正常,我做错了什么
欢迎提供任何建议或其他方法来完成此任务。我认为您缺少脚本末尾的调度程序循环:
while True:
schedule.run_pending()
time.sleep(1)
成功了谢谢,您能解释一下为什么
schedule.every(5).seconds.do(storeData)
没有成功吗schedule.every(5).seconds.do(storeData)
您只需设置scheduler对象的参数。如果不调用调度程序方法run\u pending()
时钟将不会启动