Permalink
Browse files

Initial fedmsg-tweet tool done.

  • Loading branch information...
1 parent 2c47005 commit 17ea75d331a30dda1d8df75cb6da3d36601632b5 @ralphbean committed Nov 14, 2012
Showing with 86 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +13 −0 fedmsg.d/tweet.py
  3. +71 −0 fedmsg/commands/tweet.py
  4. +1 −0 setup.py
View
@@ -8,3 +8,4 @@ dist
_build
html-output
htmldoc
+_tweet-real.py
View
@@ -0,0 +1,13 @@
+config = dict(
+ tweet_settings=dict(
+ consumer_key="get",
+ consumer_secret="these",
+ oauth_token="from",
+ oauth_token_secret="dev.twitter.com",
+ ),
+ bitly_settings=dict(
+ api_user="get this from",
+ api_key="http://bit.ly/"
+ ),
+)
+
View
@@ -0,0 +1,71 @@
+# This file is part of fedmsg.
+# Copyright (C) 2012 Red Hat, Inc.
+#
+# fedmsg is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# fedmsg is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with fedmsg; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Ralph Bean <rbean@redhat.com>
+#
+
+import twitter as twitter_api
+import bitlyapi
+
+import fedmsg
+import fedmsg.text
+from fedmsg.commands import command
+
+
+@command(name="fedmsg-tweet", extra_args=[], daemonizable=True)
+def tweet(**kw):
+ """ Rebroadcast messages to twitter """
+
+ # Boilerplate..
+ kw['publish_endpoint'] = None
+ kw['name'] = 'relay_inbound'
+ kw['mute'] = True
+
+ # Set up fedmsg
+ fedmsg.init(**kw)
+ fedmsg.text.make_processors(**kw)
+
+ # Set up twitter
+ settings = kw['tweet_settings']
+ api = twitter_api.Api(
+ settings['consumer_key'],
+ settings['consumer_secret'],
+ settings['oauth_token'],
+ settings['oauth_token_secret'],
+ )
+
+ # Set up bitly
+ settings = kw['bitly_settings']
+ bitly = bitlyapi.BitLy(
+ settings['api_user'],
+ settings['api_key'],
+ )
+
+ for name, ep, topic, message in fedmsg.tail_messages(**kw):
+ link = fedmsg.text.msg2link(message, **kw)
+ link = bitly.shorten(longUrl=link)['url']
+ message = fedmsg.text.msg2subtitle(message, **kw)
+ message = (message[:139] + " ")[:139 - len(link)] + link
+ print("Tweeting %r" % message)
+ try:
+ api.PostUpdate(message)
+ except Exception as e:
+ if 'Status is a duplicate' in str(e):
+ # Let it slide ...
+ pass
+ else:
+ raise
View
@@ -100,6 +100,7 @@
"fedmsg-config=fedmsg.commands.config:config",
"fedmsg-irc=fedmsg.commands.ircbot:ircbot",
"fedmsg-collectd=fedmsg.commands.collectd:collectd",
+ "fedmsg-tweet=fedmsg.commands.tweet:tweet",
],
'moksha.consumer': [
"fedmsg-dummy=fedmsg.consumers.dummy:DummyConsumer",

0 comments on commit 17ea75d

Please sign in to comment.