Add twitter support to statusbot
Similar to replicating to github for the convenience of our developer community, sending statuses ALSO to twitter seems like a potentially low-impact way to communicate status on an additional channel. Change-Id: Ib4bdbb335e4bc12d75d5f0ec2a1b95c8a6b2e7d5
This commit is contained in:
parent
e46fe612e7
commit
b9ea2612f7
@ -2,3 +2,4 @@ simplemediawiki
|
||||
irc
|
||||
python-daemon
|
||||
kitchen
|
||||
python-twitter
|
||||
|
@ -34,6 +34,12 @@ successpageid=2434
|
||||
|
||||
[irclogs]
|
||||
url=http://eavesdrop.example.com/irclogs/%(chan)s/%(chan)s.%(date)s.log.html
|
||||
|
||||
[twitter]
|
||||
consumer_key=consumer_key
|
||||
consumer_secret=consumer_secret
|
||||
access_token_key=access_token
|
||||
access_token_secret=access_token_secret
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@ -49,6 +55,8 @@ import simplemediawiki
|
||||
import datetime
|
||||
import re
|
||||
import ssl
|
||||
import textwrap
|
||||
import twitter
|
||||
import urllib
|
||||
|
||||
try:
|
||||
@ -149,6 +157,43 @@ class UpdateInterface(object):
|
||||
pass
|
||||
|
||||
|
||||
class Tweet(UpdateInterface):
|
||||
|
||||
def __init__(self, config):
|
||||
self.consumer_key = config.get('twitter', 'consumer_key')
|
||||
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,
|
||||
access_token_secret=self.access_token_secret)
|
||||
|
||||
def update(self, msg):
|
||||
# Limit tweets to 120 characters to facilitate retweets
|
||||
tweets = textwrap.wrap(msg, 120)
|
||||
if len(tweets) == 1:
|
||||
# Don't prefix statuses that fit
|
||||
self.api.PostUpdate(tweets[0])
|
||||
else:
|
||||
for index in range(0, len(tweets)):
|
||||
self.api.PostUpdate("{index}/{tweet}".format(
|
||||
index=index, tweet=tweets[index]))
|
||||
|
||||
def alert(self, msg=None):
|
||||
self.update(msg)
|
||||
|
||||
def notice(self, msg=None):
|
||||
self.update(msg)
|
||||
|
||||
def log(self, msg=None):
|
||||
pass
|
||||
|
||||
def ok(self, msg=None):
|
||||
self.update("Everything back to normal")
|
||||
|
||||
|
||||
class StatusPage(WikiPage, UpdateInterface):
|
||||
alert_re = re.compile(r'{{CI Alert\|(.*?)}}')
|
||||
item_re = re.compile(r'^\* (.*)$')
|
||||
@ -411,6 +456,8 @@ def _main(configpath):
|
||||
publishers = [StatusPage(config),
|
||||
AlertFile(config)]
|
||||
successlog = SuccessPage(config)
|
||||
if config.has_section('twitter'):
|
||||
publishers.append(Tweet(config))
|
||||
|
||||
bot = StatusBot(channels, nicks, publishers, successlog,
|
||||
config.get('ircbot', 'nick'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user