Taming the Python

Taming the Python

Written by Darius

Topics: Coding, Crunchbang, Linux, Openbox, Python

Hey Guys,

I’ve been learning some python over the last few weeks, thought I would give it coding a Openbox Pipe Menu a go. It’s not very useful and some of the guys in the Crunchbang Forums helped me to fix my bugs. Here is the code:

#!/usr/bin/env python -W ignore::DeprecationWarning
import sys
import cgi
import twitter

if __name__ == "__main__":
 twit = twitter.Api(username="", password="")
 status = twit.GetFriendsTimeline()
 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
 print "<openbox_pipe_menu>"
 print"    <separator label=\"Twitter\" />"

 for u in status:
    tweet = u.text
    tweet = tweet.replace("\"", "'")
    tweet = tweet.encode("utf-8")
    tweet = cgi.escape(tweet)

    print "    <menu id=\"%s\" label=\"%s\">" % (u.id, tweet)
    print "        <item label=\"View Tweet\"><action name=\"Execute\"> <execute>firefox http://twitter.com/%s/status/%s\ </execute> </action> </item>" % ( cgi.escape(u.user.screen_name), u.id)
    print "        <item label=\"Tweet by %s\" />" % (cgi.escape(u.user.name))
    print "        <item label=\"%s\" />" % (cgi.escape(u.relative_created_at))
    print "    </menu>"

 print "</openbox_pipe_menu>"
 sys.exit(0)

I don’t suggest you make use of it, this is the alpha version but I intend to add some conversation thread and caching into it at some point. I’m also learning some perl but I haven’t really made anything other than programs to test things.

I’ll try and post something tomorrow, after all the site is called Wednesday Morning.

Darius

2 Comments For This Post I'd Love to Hear Yours!

  1. Chris Says:

    Glad you are enjoying python.
    Code was a bit hard to read, as it seems the indentation got killed along the line…

  2. Darius Says:

    Yeh seems the code syntax mod has removed it all :S. I will endeavor to fix it.

    Thanks Chris!

Leave a Comment Here's Your Chance to Be Heard!