diff --git a/requirements.txt b/requirements.txt index ad81374..f214bc2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ simplemediawiki>=1.2.0b2 irc python-daemon kitchen -python-twitter>=3.4 +tweepy ib3 diff --git a/statusbot/bot.py b/statusbot/bot.py index 6801083..a795d37 100755 --- a/statusbot/bot.py +++ b/statusbot/bot.py @@ -69,7 +69,8 @@ import simplemediawiki import datetime import re import requests -import twitter +import tweepy +import textwrap import urllib try: @@ -244,14 +245,31 @@ class Tweet(UpdateInterface): self.consumer_secret = config.get('twitter', 'consumer_secret') self.access_token_key = config.get('twitter', 'access_token_key') self.access_token_secret = config.get('twitter', 'access_token_secret') - self.api = twitter.Api( - consumer_key=self.consumer_key, - consumer_secret=self.consumer_secret, - access_token_key=self.access_token_key, - access_token_secret=self.access_token_secret) + + auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret) + auth.set_access_token(self.access_token_key, self.access_token_secret) + + self.api = tweepy.API(auth) def update(self, msg): - self.api.PostUpdates(msg, continuation=u'\u2026') + # NOTE(ianw) python-twitter, used originally, used to do some + # automated splitting. It didn't account for emoji, + # link-shortening, etc. Ergo, this could be better, but KISS + # for now + tweets = textwrap.wrap(msg, 270) + if len(tweets) > 1: + for i in range(0, len(tweets)): + tweet = tweets[i] + tweets[i] = tweet + " %d/%d" % (i+1, len(tweets)) + + last_tweet = None + for tweet in tweets: + if not last_tweet: + last_tweet = self.api.update_status(status=tweet) + else: + last_tweet = self.api.update_status(status=tweet, + in_reply_to_status_id = last_tweet.id, + auto_populate_reply_metadata=True) def alert(self, msg=None): self.update(msg)