我试图每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 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)
https://pypi.python.org/pypi/schedule