twitools/filler.py

31 lines
823 B
Python
Executable file

#!/usr/bin/env python3
import dbtools, setuptools, twitools
def fill(db=dbtools.dbObject(), user=twitools.twObject().whoami(), two=twitools.twObject()):
query = "from:" + user
savepoint = db.getLatestTweet()
last = savepoint
timeline = two.search(query, savepoint)
tw_counter = 0
for status in timeline:
timestamp = status.created_at.strftime('%Y-%m-%d %H:%M:%S') + " +0000"
text = setuptools.unescapeText(status.text)
db.executeQuery("INSERT INTO tweets('tweet_id','timestamp','text') VALUES(" + str(status.id) + ",'" + timestamp + "','" + text + "')")
db.commit()
last = status.id
tw_counter = tw_counter + 1
db.closeConnection()
return tw_counter, last, savepoint
if __name__ == "__main__":
count, last, first = fill()
print("Stored %i tweets after %i until %i." % (count, first, last))