Skip to content Skip to sidebar Skip to footer

Python Tweepy Writing To Sqlite3 Db

My script below (taken from various resources online) isn't writing to the database. I do not get any errors, and if I comment out the database lines then it outputs to the consol

Solution 1:

First, fix your indentation. You are not getting any errors, because you're explicitly silencing them! with

except Exception, e:
    # Catch any unicode errors while printing to console# and just ignore them to avoid breaking application.pass

This catches any exception that occurs in the try: except: block. Reading the Python Tutorial is a good start to learn more about exceptions.

Solution 2:

Do you want to do this:

cur = conn.cursor()
cursor.execute('INSERT INTO tweets (text, date) VALUES (?, NOW())' ,(status.text))

Or this:

cur = conn.cursor()
cur.execute('INSERT INTO tweets (text, date) VALUES (?, NOW())' ,(status.text))

In the First case cursor is undeclared.

Also, as lqc pointed out, you silence all errors. Don't catch any exceptions to see what's going on or change it to something more specific (like UnicodeError).

Post a Comment for "Python Tweepy Writing To Sqlite3 Db"