-
Notifications
You must be signed in to change notification settings - Fork 0
/
herobot.py
149 lines (107 loc) · 4.89 KB
/
herobot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python2
# -*- coding: utf-8 -*- #
from hero import make_hero
from hero import get_image
from hero import get_image_url
from twitterbot import TwitterBot
class MyTwitterBot(TwitterBot):
def bot_init(self):
"""
Initialize and configure your bot!
Use this function to set options and initialize your own custom bot
state (if any).
"""
############################
# REQUIRED: LOGIN DETAILS! #
############################
self.config['api_key'] = '%API_KEY%'
self.config['api_secret'] = '%API_SECRET%'
self.config['access_key'] = '%ACCESS_KEY%'
self.config['access_secret'] = '%ACCESS_SECRET%'
######################################
# SEMI-OPTIONAL: OTHER CONFIG STUFF! #
######################################
# how often to tweet, in seconds
self.config['tweet_interval'] = 20 * 60 # default: 30 minutes
# use this to define a (min, max) random range of how often to tweet
# e.g., self.config['tweet_interval_range'] = (5*60, 10*60) # tweets every 5-10 minutes
self.config['tweet_interval_range'] = None
# only reply to tweets that specifically mention the bot
self.config['reply_direct_mention_only'] = False
# only include bot followers (and original tweeter) in @-replies
self.config['reply_followers_only'] = True
# fav any tweets that mention this bot?
self.config['autofav_mentions'] = False
# fav any tweets containing these keywords?
self.config['autofav_keywords'] = []
# follow back all followers?
self.config['autofollow'] = False
###########################################
# CUSTOM: your bot's own state variables! #
###########################################
# If you'd like to save variables with the bot's state, use the
# self.state dictionary. These will only be initialized if the bot is
# not loading a previous saved state.
# self.state['butt_counter'] = 0
# You can also add custom functions that run at regular intervals
# using self.register_custom_handler(function, interval).
#
# For instance, if your normal timeline tweet interval is every 30
# minutes, but you'd also like to post something different every 24
# hours, you would implement self.my_function and add the following
# line here:
# self.register_custom_handler(self.my_function, 60 * 60 * 24)
def on_scheduled_tweet(self):
"""
Make a public tweet to the bot's own timeline.
It's up to you to ensure that it's less than 140 characters.
Set tweet frequency in seconds with TWEET_INTERVAL in config.py.
"""
# text = function_that_returns_a_string_goes_here()
# self.post_tweet(text)
text = make_hero()
image = get_image(get_image_url(text))
self.post_tweet(text, media=image)
def on_mention(self, tweet, prefix):
"""
Defines actions to take when a mention is received.
tweet - a tweepy.Status object. You can access the text with
tweet.text
prefix - the @-mentions for this reply. No need to include this in the
reply string; it's provided so you can use it to make sure the value
you return is within the 140 character limit with this.
It's up to you to ensure that the prefix and tweet are less than 140
characters.
When calling post_tweet, you MUST include reply_to=tweet, or
Twitter won't count it as a reply.
"""
# text = function_that_returns_a_string_goes_here()
# prefixed_text = prefix + ' ' + text
# self.post_tweet(prefix + ' ' + text, reply_to=tweet)
# call this to fav the tweet!
# if something:
# self.favorite_tweet(tweet)
pass
def on_timeline(self, tweet, prefix):
"""
Defines actions to take on a timeline tweet.
tweet - a tweepy.Status object. You can access the text with
tweet.text
prefix - the @-mentions for this reply. No need to include this in the
reply string; it's provided so you can use it to make sure the value
you return is within the 140 character limit with this.
It's up to you to ensure that the prefix and tweet are less than 140
characters.
When calling post_tweet, you MUST include reply_to=tweet, or
Twitter won't count it as a reply.
"""
# text = function_that_returns_a_string_goes_here()
# prefixed_text = prefix + ' ' + text
# self.post_tweet(prefix + ' ' + text, reply_to=tweet)
# call this to fav the tweet!
# if something:
# self.favorite_tweet(tweet)
pass
if __name__ == '__main__':
bot = MyTwitterBot()
bot.run()