import argparse, tools def getSavepoint(db, user): db.executeQuery("SELECT MAX(tweet_id) FROM retweets WHERE LOWER(author) = '%s'" % user.lower()) 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) and status.text[0:2] != "RT": timestamp = status.created_at.strftime('%Y-%m-%d %H:%M:%S') + " +0000" text = unescapeText(status.text) db.executeQuery("INSERT INTO retweets('id','author','created_at','text') VALUES(" + str(status.id) + ",'" + user.lower() + "','" + 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:])