The thoughts of a web 2.0 research fellow on all things in the technological sphere that capture his interest.

Sunday 31 August 2008

Twittering with Python ...on the web

Programming is really addictive, especially when you are bad at it. Whilst the proficient programmer can deal with their problems in a matter of minutes, bad programmers can spend hours on the simplest of problems. Today I decided to start messing about with some server-side programming for the first time; now I find myself wondering what happened to my Sunday.

This particular form allows anyone to post to your Twitter account (and then displays the comments that have already been posted):

Enter Comment:



Now all I need to do is think of a use for anonymous twittering....
(http://twitter.com/blogcomments)

The code:
>#!/usr/bin/python
>import cgi
>import urllib
>print "Content-type: text/html\n\n"
>form=cgi.FieldStorage()
>data = urllib.urlencode({"status" : form["status"].value})
>res = urllib.urlopen("http://USERNAME:PASSWORD@twitter.com/statuses/update.xml"
, data)
>lines = urllib.urlopen('http://twitter.com/statuses/user_timeline/16066835.rss')
.readlines()
>for line in lines:
>>>if line.find('title') <>-1:
>>>>>>line=line[11:(len(line)-9)]
>>>>>>print line

Labels: , ,

posted by David at

1 Comments:

Anonymous Anonymous said...

hey, fun. I did similar with php on my server at home, all so I could get the computer to change my twitter user pic every couple of hours. It turns out the twitter folks use curl to test stuff and there was a nice example on their developer site.
Maybe I should make the picture reflect the time of day in my locale, but I'm just not bored enough to do something sensible with it yet. :)

25 February 2009 at 10:53

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home