twitools/filler.py
2016-04-08 00:15:21 +02:00

31 lines
783 B
Python
Executable file

#!/usr/bin/env python3
import dbtools, tools
def fill(db=dbtools.dbObject(), user=tools.user(), two=tools.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 = tools.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))