Posted by: Buzz in python, twitter
Some two months after the fact, I thought it may well be time to post a blog on this little code snippet.
As some of you have noticed every commit message to my subversion repository is infact updating my twitter.
This code was uploaded to subversion on 10/06/2009, so sorry for the late write up!
Requirements
Python 2.5 or higher
Subversion server
Installation
- svn co http://svn.saiweb.co.uk/branches/python/svn_tweeter.py /usr/bin/svn_tweeter
- chmod +x /usr/bin/svn_tweeter
- cd /path/to/svn/hooks
- Edit post-commit with your favorite text editor
1 2 3 4
| REPOS="$1"
REV="$2"
/usr/bin/python /usr/bin/svn_tweeter -u twitterusername -p twitterpassword -r $REV -s $REPOS |
Now try a commit, and check your syslog for entries from the script.
Aug 24 11:36:26 132 python: SVN_TWEETER: http://twitter.com/statuses/update.json query complete
Tags:
hooks,
post-commit,
Subversion,
svn,
twitter
No Comments »
Posted by: Buzz in python
After taking another look at Python I am quickly coming to love it, as an “exercise” in re-learning python I decided to write a very simple command line “tweeter” this uses the Twitter API to update your twitter status, extending from the “update twitter in a single line”
You can grab a copy of the script from here: http://svn.saiweb.co.uk/branches/python/tweet.py
Example usage:
1
| ./tweet.py -u username -p password -t your tweet goes here |
If you want to parse the JSON data normally returned after submitting a new tweet simply add the -j flag.
If you are prompted for a username and password when running this script the username and password supplied using the -u and -p flags was incorrect.
Tags:
python,
twitter
1 Comment »
Posted by: Buzz in Linux
As it turns out twitter account can be updated in a single line, this makes writing “bots” just that little bit easier.
1
| /usr/bin/curl --basic --user "username:password" --data-ascii "your tweet" http://twitter.com/statuses/update.json |
This also returns JSON should you want to parse the reply data.
i.e.
1
| {"in_reply_to_screen_name":null,"in_reply_to_status_id":null,"truncated":false,"user":{"profile_image_url":"http:\/\/static.twitter.com\/images\/default_profile_normal.png","description":"","followers_count":0,"screen_name":"user","url":null,"name":"user","protected":true,"location":"","id":12345678},"text":"your tweet","favorited":false,"created_at":"Fri Mar 20 11:38:44 +0000 2009","in_reply_to_user_id":null,"id":1359757870,"source":"web"} |
At the moment I am looking at hooking this into Nagios, from there the feed will be passed into a ’service status page’.
But in theory this single line could be used for any purpose.
Tags:
twitter
2 Comments »