2015-04-13 20:58:32 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2016-05-30 18:40:21 +00:00
|
|
|
import dbtools, setuptools, twitools
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2016-05-30 18:40:21 +00:00
|
|
|
def fill(db=dbtools.dbObject(), user=twitools.twObject().whoami(), two=twitools.twObject()):
|
2015-04-22 00:06:32 +00:00
|
|
|
query = "from:" + user
|
2016-04-07 22:15:21 +00:00
|
|
|
savepoint = db.getLatestTweet()
|
2015-04-22 00:06:32 +00:00
|
|
|
last = savepoint
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2015-04-22 00:06:32 +00:00
|
|
|
timeline = two.search(query, savepoint)
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2015-04-15 22:53:15 +00:00
|
|
|
tw_counter = 0
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2015-04-15 22:53:15 +00:00
|
|
|
for status in timeline:
|
|
|
|
timestamp = status.created_at.strftime('%Y-%m-%d %H:%M:%S') + " +0000"
|
2016-05-30 18:40:21 +00:00
|
|
|
text = setuptools.unescapeText(status.text)
|
2015-04-22 00:06:32 +00:00
|
|
|
|
|
|
|
db.executeQuery("INSERT INTO tweets('tweet_id','timestamp','text') VALUES(" + str(status.id) + ",'" + timestamp + "','" + text + "')")
|
|
|
|
db.commit()
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2015-04-15 22:53:15 +00:00
|
|
|
last = status.id
|
|
|
|
tw_counter = tw_counter + 1
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2015-04-22 00:06:32 +00:00
|
|
|
db.closeConnection()
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2015-04-15 22:53:15 +00:00
|
|
|
return tw_counter, last, savepoint
|
2015-03-09 17:32:24 +00:00
|
|
|
|
2015-04-15 22:53:15 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
count, last, first = fill()
|
|
|
|
print("Stored %i tweets after %i until %i." % (count, first, last))
|
2016-05-30 18:40:21 +00:00
|
|
|
|