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) api.update_status("@%s Sorry, ich verstehe deinen Tweet nicht... :(" % sender, twid)
continue 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() cur.commit()
savepoint = twid savepoint = twid

View file

@ -14,7 +14,7 @@ if os.path.isfile(file):
conn = sqlite3.connect(file) conn = sqlite3.connect(file)
curs = conn.cursor() 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.commit()
conn.close() conn.close()

View file

@ -23,14 +23,15 @@ sql_conn = sqlite3.connect(database_filename)
cur = sql_conn.cursor() cur = sql_conn.cursor()
while True: 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: for status in values:
original = int(status[0]) original = int(status[0])
recipient = status[2] recipient = status[2]
comment = status[3] comment = status[3]
try: try:
api.update_status("@%s Es wär soweit... :)" % recipient, original) 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: except:
pass pass