The Indian train system is amazing considering the number of passengers it hauls around the country but it can be frustrating as a foreigner trying to book tickets, especially at the last minute.
Certain trains have tickets put aside for foreign tourists. This is fantastically useful given that most trains sell out well in advance but discovering which trains have foreign tourist quota tickets available is problematic as online booking agents don’t have the information – you can only buy them at stations. The process invariably involves the following steps:
- Navigate to Cleartrip site.
- Enter journey details and submit.
- Discover no trains run between the two chosen stations (Cleartrip only searches direct routes).
- Repeat step 2 until you get some results.
- Note down the train number and figure out the short codes for the departing and arriving stations.
- Navigate to the seat availability form on the Indian Rail website.
- Enter journey details and submit.
- Find you’ve entered something wrong – very likely given how exacting the form is.
- Go back, amend details and submit form.
- Find the site has reset the date of travel you put in.
- Repeat step 9.
- Repeat steps 8 through 11 once or twice.
- No foreign tourist quota tickets for this train.
- Go back to step 5.
If there are 20 trains on a given day for your route, checking each one manually becomes unfeasible.
Instead, I wrote a Greasemonkey script that automates the Indian Rail website portion of the process and reports the results right in my Cleartrip results page. What might have taken thirty minutes for each journey (and as I have no firm travel plans I’ve been checking a lot of journeys) now takes seconds. Itch scratched.
Another little automation project I recently completed was prompted by one of my guesthouses’ ISPs. To use the WiFi you were first required to log into a web page. Unfortunately, unless you kept the login page open, the session would frequently time out requiring another visit to the login page. Rather than doing this manually every time I discover I’d been logged out, I wrote a simple Python script to perform the task for me.
All it does is mimics the keepalive request that the login page performs once you’ve logged in. If the script detects the session has timed out anyway, it posts the login details to the ISP. This may not sound like a big win but when you’re working all day and the session is timing out several times an hour, it saved me going prematurely bald.
These two scripts only took me a couple of enjoyable hours to build, taught me more about the languages and domains I wrote them in and, most importantly, unlike the experience in the above XKCD comic, have saved me a lot of time.
Teaching the world to scratch their itches
A lot has been said of late about the value of teaching schoolchildren to code as the UK Government launched its Year of Code initiative earlier this year, although not without some controversy.
One of the reasons I love being a programmer is having the ability to solve problems by bashing out a few lines of code. Not only does this make my life easier but I get to enjoy the process as well.
My skills mean I’m able to recognise and understand a problem and come up with the solution, not just because I know a handful of programming languages (although that obviously helps) but because of the knowledge programming has given me about the world of technology and how it works.
My hope for the Year of Code is not that a whole generation decides they want to become the next Zuckerburg but that youth are given the tools to understand the technology that the world is increasingly reliant on and be able to make it serve their needs.
If that also results in someone being more likely to create the next Facebook, so much the better.