Skip to content

Commit a7ac001

Browse files
author
Dave Bell
authored
added auto-favorite and replies, to replies
1 parent db5f67e commit a7ac001

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

loremricksum.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,47 @@
1212
api = tweepy.API(auth)
1313
url = 'http://loremricksum.com/api/?paragraphs=1&quotes=1'
1414

15-
def runBot():
15+
def getQuote():
1616
quote = urllib.request.urlopen(url).read().decode('UTF-8')
1717
text = json.loads(quote)['data']
1818
tweet = json.dumps(text).strip("[]")
19-
api.update_status(tweet)
19+
return tweet
20+
21+
def tweetQuote():
22+
msg = getQuote()
23+
api.update_status(msg)
24+
25+
def tweetReply(username, status_id):
26+
reply = getQuote()
27+
reply_status = "@%s %s" % (username, reply)
28+
api.update_status(status = reply_status, in_reply_to_status_id = status_id)
29+
30+
def favorite(status_id):
31+
api.create_favorite(status_id)
32+
33+
class BotStreamer(tweepy.StreamListener):
34+
35+
def on_status(self, status):
36+
try:
37+
username = status.user.screen_name
38+
status_id = status.id
39+
favorite(status_id)
40+
tweetReply(username, status_id)
41+
except tweepy.TweepError as e:
42+
print((e.reason))
43+
tweetReply(username, status_id)
44+
45+
myStreamListener = BotStreamer()
46+
47+
stream = tweepy.Stream(auth, myStreamListener)
48+
stream.filter(track=['@loremricksum'], async=True)
2049

2150
while True:
22-
try:
23-
runBot()
51+
try:
52+
tweetQuote()
2453
except tweepy.TweepError as e:
2554
print((e.reason))
26-
runBot()
55+
tweetQuote()
2756
time.sleep(3600)
2857

58+

0 commit comments

Comments
 (0)