60 lines
1.5 KiB
Python
Executable file
60 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import HTMLParser, tweepy, os, sqlite3, time, random
|
|
|
|
# Notice: You may want to create seperate apps (or even accounts) for
|
|
# the getter and the tweeter.
|
|
|
|
# For larger user bases, consider using multiple tweeter accounts.
|
|
|
|
cke = "Consumer Key"
|
|
cse = "Consumer Secret"
|
|
ato = "Access Token"
|
|
ase = "Access Secret"
|
|
|
|
database_filename = "Database.db"
|
|
|
|
auth = tweepy.OAuthHandler(cke, cse)
|
|
auth.set_access_token(ato, ase)
|
|
api = tweepy.API(auth)
|
|
|
|
sql_conn = sqlite3.connect(database_filename)
|
|
cur = sql_conn.cursor()
|
|
|
|
while True:
|
|
values = cur.execute("SELECT * FROM tweets WHERE datetime(timestamp) < datetime('now','localtime') AND sent = 0")
|
|
for status in values:
|
|
original = int(status[0])
|
|
recipient = status[2]
|
|
comment = status[3]
|
|
try:
|
|
greeting = random.randint(1,9)
|
|
if greeting == 1:
|
|
text = "Es ist soweit."
|
|
elif greeting == 2:
|
|
text = "Die Zeit ist gekommen."
|
|
elif greeting == 3:
|
|
text = "Los geht's."
|
|
elif greeting == 4:
|
|
text = "Du wolltest geweckt werden. Ich wecke."
|
|
elif greeting == 5:
|
|
text = "*aufweck*"
|
|
elif greeting == 6:
|
|
text = "Hopp, aufstehen!"
|
|
elif greeting == 7:
|
|
text = "*BUMM*"
|
|
elif greeting == 8:
|
|
text = "Guten Tag. Hier spricht die Polizei!"
|
|
else:
|
|
text = "Guten Morgen. :P"
|
|
|
|
api.update_status("@%s %s" % (recipient, text), original)
|
|
cur.execute("UPDATE tweets SET sent = 1 WHERE tweet_id = %i" % original)
|
|
sql_conn.commit()
|
|
except Exception, e:
|
|
print "Error in " + str(twid)
|
|
print e
|
|
pass
|
|
|
|
time.sleep(10)
|