Python for day-to-day tasks: the webbrowser module

auto

An initiative at work requires me to analyze a large spreadsheet of data. One of the columns contains a csv-separated list of bugs that I need to take a look at. Normally, this would be a painful job of copying each defect and pasting it in the browser repeatedly. When hundreds of rows needed analysis, each involving multiple defect IDs,  I switched to python to ease my pain.

I knew where to look because of this cute easter-egg in python:

import antigravity

The help text for this module led me to the library, c:python33libantigravity.py in my case. The webbrowser module imported here showed how easy it is to launch a browser tab by passing a URL from python:

import webbrowser
import hashlib

webbrowser.open(“http://xkcd.com/353/”)

This was all I need for my job as well. I wrote a 10 line script that basically:

  1. asked the user for input (in my case a comma separated list of defects),
  2. converted the input to a list and stripped unneeded whitespace,
  3. iterated through this list and appended the defect ID to the base URL, and
  4. called the webbrowser module to open the tabs.

The resulting script looks like this:

import webbrowser

bugs=input(‘Paste the list of bugs:n’)
buglist=bugs.split(‘,’)

for i,x in enumerate(buglist):
buglist[i]=x.strip()

for i in buglist:
url=”+i+”
webbrowser.open(url)

And that’s it! A half-dozen tabs open immediately and I can move on to analyzing them. Python has proved to be a boon in my daily job for quick and dirty scripts like this.

Collusion

collusion-thumb-500x392-15

The folks at the Guardian released a Firefox addon recently. Called Collusion, it silently tracks third party sites that track users across multiple sites. I’ve run it for something like two days so far, and its depressing how I’ve littered my trail all over the web. The UI is very nicely done, and highlighting an icon shows all the sites it connects to and greys out the rest.

Related articles

Enhanced by Zemanta

Opera 9 is mind blowing

I’ve been trying out Opera 9 the past few days, and I have to say I’m very impressed. Check out the size of the binaries in their website, its a meagre 5 MB file. The amount of features they’ve squeezed into that tiny size is just incredible. For starters.. its fast. Just for that one reason alone, I consider it worth the switch. Firefox struggles in my ageing comp, and I usually use Lynx or Dillo for a quick visit to the ‘net. Opera launches in a flash, in comparison.

 Features: Well, lets start with the in-built bittorrent client it has. Click on a torrent file and it gets launched automatically. Some config options are also available, so its a pretty useful feature for the lazy. And then there’s this very impressive mail client. It took me a couple of quick steps to get my gmail set up, and its seriously cool feature-wise. Its got labels, gmail style, isntead of the usual folders, and you can also read newsfeeds from the same place.

The usability features are just amazing. The keybindings are extensive, and I’ve already gotten a few favourites (Shift+Arrow keys to traverse links in a page, F8/F9 to switch to URL bar/page). The mouse gestures are pretty neat too, and work pretty fast unlike what I’d expected. There are the usual search engine keywords as well, I always prefer them to the search bar on top.

Extensions: um, there aren’t any. Perhaps its a good thing in a way, its nice to have different browsers with different featuresets I guess. Among the Firefox extensions I use most often, session-saving, undo-closed-tabs, and adblock are all in-built in Opera. I can live without the gmail manager extension as well, since I’m using Opera’s mail client itself. My biggest concern is that I don’t have the Foxmarks bookmarks sync extension with me now. I’ll probably have to look around for a workaround there. As an alternative to extensions, Opera does have widgets. I personally don’t use them (my window manager (Ion3) gives a full screen for each widget), but I had a look at a few and they were pretty nice.

Summary: I’m sticking with Opera at home, I’ve still not decided about the office. Its a really neat competitor to Firefox, and I should’ve probably tried this a long time back. Apart from very minor problems (its closed source, some people might not like that; some keybindings don’t seem to work at times, etc), Opera 9 has enough features to make it one helluva browser.
P.S. Go to this link after installing Opera, and press F11. Those guys sure think up some neat stuff.