Twitter and tty.cl
Table of Contents
1 Why Twitter?
2 How does it works?
Easy, as we use GNU Emacs + Org Mode + Git to create our site we just need to add a hook which will be the responsible to publish on Twitter every time we commit a new article, well this was done with Python.
So, just a hook and some OAuth and the magic ended like this
## ## post-commit-twitter.py ## Login : <zeus@jilguero.emacs.cl> ## Started on Tue Jun 21 10:24:18 2011 Jonathan Gonzalez V. ## $Id$ ## ## Copyright (C) 2011 Jonathan Gonzalez V. ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program 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 General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import os import sys import re import tweepy tty_web = 'http://tty.cl/' commit_cmd = "git show --name-only" commit_res = os.popen( commit_cmd, 'r' ) commit_line = commit_res.readlines() commit_line.pop(0) # We remove the commit line, we don't need it author_line = commit_line.pop(0) date_line = commit_line.pop(0) # We need to extract the comment line, do we want it? :P still = True commit_line.pop(0) while( still ): l = commit_line.pop(0) if l == '\n': still = False # Now it's time to get how many areticles are in this commit articles = [] for fc in commit_line: s = re.search( '^article', fc ) if s is not None: articles.append(fc) # We will not publish on Twitter anything but articles if len( articles ) is 0: exit # Do I need to explain this part? :D author = re.split( ' <.*>', author_line.split(': ')[1] )[0] # Prepare the tweet tweet = author + ' has just added/updated one or more articles.' # Oh yes, we want links! for article in articles: article = article.replace( '.org\n', '.html' ) tweet += ' '+tty_web+article # And the Twitter thing! twitter_auth = tweepy.OAuthHandler( 'consumer_token', 'consumer_secret' ) twitter_auth.set_access_token('access_key', 'access_secret' ) twitter_api = tweepy.API(twitter_auth) twitter_api.update_status( tweet )
3 Some problems with OAuth
With Twitter you need to grant access to an app, this means that the app will redirect you to twitter, you grant the access to the app and then you can, from you app start to publish in the timeline of your Twitter account, this tiny brief of how OAuth works.
We cannot follow this process when you are using a hook so we mail to the Twitter support team asking them to enable the xAuth for our app, well they say that they will not do this but they will point to us to a one time auth process which give us our accesskey and accesssecret key for our app, this was very useful and nice, we can do all the things that you can do with OAuth but not going through the whole OAuth process, nice!.
4 Future
This was a work less than an hour so isn't complete yet, we will keep working on some improvements like publish or snippets codes and things like that =)
Generated by Org version 7.5 with Emacs version 23 on 2011-06-29 16:40:14 UTC
Copyright © 2011 tty team
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.