Add retweeter, aka erdlofbot

This commit is contained in:
Klaus-Uwe Mitterer 2016-12-06 22:42:06 +01:00
parent 2fba8e12b5
commit 81c7f7309b

41
retweeter.py Normal file
View file

@ -0,0 +1,41 @@
import argparse, tools
def getSavepoint(db, user):
db.executeQuery("SELECT max(tweet_id) FROM retweets WHERE author = '%s'" % user)
try:
return int(db.getNext()[0])
except:
print("No tweets from %s stored yet." % user)
return 0
def retweet(user, two=tools.twObject(), db=tools.dbHelper(tools.dbpath())):
query = "from:" + user
savepoint = getSavepoint(db, user)
last = savepoint
timeline = two.search(query, savepoint)
tw_counter = 0
for status in timeline:
if status.text[0] != "@" or two.whoami() in status.text:
timestamp = status.created_at.strftime('%Y-%m-%d %H:%M:%S') + " +0000"
text = unescapeText(status.text)
db.executeQuery("INSERT INTO retweets('id','created_at','text') VALUES(" + str(status.id) + ",'" + timestamp + "','" + text + "')")
db.commit()
two.retweet(status.id)
last = status.id
tw_counter = tw_counter + 1
db.closeConnection()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("user", help="handle (user name) of the source user")
user = parser.parse_args().user
retweet(user if user[0] != "@" else user[1:])