Hacking Python

I was asked to help solve a problem today, involving checking the voter registration status of a database of voters against a web-form. This is not a totally straight-forward scripting issue as the web-form contains a randomly generated key and a number of other values that need to be included in the query. So, any program written would need to have a bit of smarts.

It was designed that way, don’t ask me why.

So, I thought to myself, this would be a good opportunity to learn some Python! Honestly, I have never written any Python before and I thought that since Python was a great scripting language to hack stuff together quickly, I should try to see if I could do this in Python. To make it a little challenging, I gave myself two hours to finish it (the length of free time I had while sitting at a local pasar malam this evening).

So, I started by looking up the official Python examples on how to form a HTTP query – straightforward and easy with Python. Then, I did some text processing on the return results to grep the various random keys. Next, I followed the official examples on how to perform a HTTP post. Finally, I used the official examples on how to process a CSV file and perform the checkup under a sub-routine inside a loop.

It took me just an hour to finish the script. I think that this is more of a reflection on the ease of use of Python, rather than my skills. I have just proven to myself that it is possible for me to pick up a new language and accomplish something useful with it in under an hour. Amazing.

Anyway, the code isn’t totally pretty but it is available at github.

Published by

Shawn Tan

Chip Doctor, Chartered Engineer, Entrepreneur, Law Graduate.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s