0

i'm trying to schedule a task every 5 seconds, here what i did:

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()

but the storeData method is not reachable.. if i run storeData() instead of schedule.every(5).seconds.do(storeData) the code work perfectly, what i'm doing wrong

any suggesting or other ways to do this task are welcome.

Mounir Elfassi
  • 2,242
  • 3
  • 23
  • 38

1 Answers1

3

I think you are missing the scheduler loop at the end of your script:

while True:
   schedule.run_pending()
   time.sleep(1)

https://pypi.python.org/pypi/schedule

lukaz
  • 84
  • 4
  • it worked Thank you, can you please explain why `schedule.every(5).seconds.do(storeData)` didn't work – Mounir Elfassi Sep 22 '15 at 11:02
  • by `schedule.every(5).seconds.do(storeData)` you just a set the parameters for scheduler object. Without calling scheduler method `run_pending()` the clock is not started – lukaz Sep 22 '15 at 11:09