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

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home