Store old tweets rather than deleting them.

This commit is contained in:
Klaus-Uwe Mitterer 2015-03-18 22:42:54 +01:00
parent 400995fc03
commit 753d4fc820
3 changed files with 5 additions and 4 deletions

View file

@ -47,7 +47,7 @@ while True:
api.update_status("@%s Sorry, ich verstehe deinen Tweet nicht... :(" % sender, twid)
continue
cur.execute("INSERT INTO tweets VALUES(%i,'%s','%s','%s')" % (twid,date.strftime("%Y-%m-%dT%H:%M:%S"),sender,comment))
cur.execute("INSERT INTO tweets VALUES(%i,'%s','%s','%s',0)" % (twid,date.strftime("%Y-%m-%dT%H:%M:%S"),sender,comment))
cur.commit()
savepoint = twid

View file

@ -14,7 +14,7 @@ if os.path.isfile(file):
conn = sqlite3.connect(file)
curs = conn.cursor()
curs.execute("CREATE TABLE tweets(tweet_id numeric, timestamp text, sender text, comment text);")
curs.execute("CREATE TABLE tweets(tweet_id numeric, timestamp text, sender text, comment text, sent numeric);")
conn.commit()
conn.close()

View file

@ -23,14 +23,15 @@ sql_conn = sqlite3.connect(database_filename)
cur = sql_conn.cursor()
while True:
values = cur.execute("SELECT * FROM tweets WHERE timestamp < datetime('now')")
values = cur.execute("SELECT * FROM tweets WHERE timestamp < datetime('now') AND sent = 0")
for status in values:
original = int(status[0])
recipient = status[2]
comment = status[3]
try:
api.update_status("@%s Es wär soweit... :)" % recipient, original)
cur.execute("DELETE FROM tweets WHERE tweet_id = %i" % original)
cur.execute("UPDATE tweets SET sent = 1 WHERE tweet_id = %i" % original)
cur.commit()
except:
pass