The code below is streaming the twitter public timeline for a variable which output any tweets to the console. I\'d like the save the same variables (status.text, status.aut
I'm quite new to tweepy . But these are the modifications that worked for me . You need to add VALUES after INSERT INTO TWEETS . Also , don't forget to commit the changes . This is the link I referred to : related post
cur.execute("INSERT INTO TWEETS VALUES(?, ?, ?, ?)", (status.text,
status.author.screen_name,
status.created_at,
status.source))
con.commit()
You are missing a closing parenthesis on the last line of the following code (lines 34–37 from what you posted):
cur.executemany("INSERT INTO TWEETS(?, ?, ?)", (status.text,
status.author.screen_name,
status.created_at,
status.source)
Just add a parenthesis to close the method call immediately after your tuple parameter.
import sqlite3 as lite
con = lite.connect('test.db')
cur = con.cursor()
cur.execute("CREATE TABLE TWEETS(txt text, author text, created int, source text)")
then later:
cur.executemany("INSERT INTO TWEETS(?, ?, ?, ?)", (status.text,
status.author.screen_name,
status.created_at,
status.source))
Full disclosure: still new to this stuff. However, I got your code working by changing it to:
cur.execute("INSERT INTO TWEETS VALUES(?,?,?,?)", (status.text, status.author.screen_name, status.created_at, status.source))
con.commit()
It seems to me that you're reading in one status at a time. The executemany method would be for when you have more than one status. For example:
(['sometext', 'bob','2013-02-01','Twitter for Android'], ['someothertext', 'helga', '2013-01-31', 'MacSomething'])
I'm definitely not a wizard and am not sure what sort of impact the commit() has on every entry... I'm guessing the performance is terrible, but it works for a single term in the query.
Thanks for posting your code, I finally learned how to do streaming.