twitter: method for polling mentions timeline
not stitched together in this commit, so it'll work but it won't be started
This commit is contained in:
parent
6cbf5f3d96
commit
3b78e9b894
@ -28,6 +28,8 @@ class Twitter(Plugin):
|
|||||||
self.temp_token = None
|
self.temp_token = None
|
||||||
self.temp_token_secret = None
|
self.temp_token_secret = None
|
||||||
|
|
||||||
|
self.poll_mentions = False
|
||||||
|
|
||||||
super(Twitter, self).__init__(bot, connection, event)
|
super(Twitter, self).__init__(bot, connection, event)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
@ -79,6 +81,8 @@ class Twitter(Plugin):
|
|||||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_auth)
|
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_auth)
|
||||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_replyto)
|
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_replyto)
|
||||||
|
|
||||||
|
self.poll_mentions = False
|
||||||
|
|
||||||
super(Twitter, self).stop()
|
super(Twitter, self).stop()
|
||||||
|
|
||||||
def handle_getstatus(self, connection, event, match):
|
def handle_getstatus(self, connection, event, match):
|
||||||
@ -232,6 +236,29 @@ class Twitter(Plugin):
|
|||||||
log.error("twitter settings object does not exist")
|
log.error("twitter settings object does not exist")
|
||||||
return self.bot.reply(event, "twitter module not configured")
|
return self.bot.reply(event, "twitter module not configured")
|
||||||
|
|
||||||
|
def thread_watch_mentions(self, sleep_time=60):
|
||||||
|
"""Poll mentions from Twitter every sleep_time seconds.
|
||||||
|
|
||||||
|
:param sleep_time: second to sleep between checks
|
||||||
|
:type sleep_time: int
|
||||||
|
"""
|
||||||
|
|
||||||
|
while self.poll_mentions:
|
||||||
|
twittersettings = TwitterClient.objects.get(pk=1)
|
||||||
|
out_chan = twittersettings.mentions_output_channel.name
|
||||||
|
since_id = twittersettings.mentions_since_id
|
||||||
|
|
||||||
|
mentions = self.twit.get_mentions_timeline(since_id=since_id)
|
||||||
|
for mention in mentions:
|
||||||
|
reply = self._return_tweet_or_retweet_text(tweet=mention, print_source=True)
|
||||||
|
self.bot.privmsg(out_chan, reply)
|
||||||
|
since_id = mention['id'] if mention['id'] > since_id else since_id
|
||||||
|
|
||||||
|
twittersettings.mentions_since_id = since_id
|
||||||
|
twittersettings.save()
|
||||||
|
|
||||||
|
time.sleep(sleep_time)
|
||||||
|
|
||||||
def _reply_with_tweet_or_retweet_text(self, event, tweet, print_source=False, print_id=True):
|
def _reply_with_tweet_or_retweet_text(self, event, tweet, print_source=False, print_id=True):
|
||||||
"""Do a bot.reply() with the appropriate text representation of the given tweet.
|
"""Do a bot.reply() with the appropriate text representation of the given tweet.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user