Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
安排不在Python中工作的任务_Python_Scheduled Tasks_Feedparser - Fatal编程技术网

安排不在Python中工作的任务

安排不在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

我试图每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)

成功了谢谢,您能解释一下为什么
schedule.every(5).seconds.do(storeData)
没有成功吗
schedule.every(5).seconds.do(storeData)
您只需设置scheduler对象的参数。如果不调用调度程序方法
run\u pending()
时钟将不会启动