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):
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: programming, Python, Twitter
1 Comments:
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