Douwe Osinga's Blog: Amtrak discounts

Saturday, June 16, 2007

We're in the US. Among other things, the US in the country of coupons – pieces of paper you can cut from a newspaper that get you a discount. Nowadays, these things are online too, usually in the form of a code that you can enter when you want to book online. We wanted to take the train from New York up to Niagara Falls and I found this discount code that gave me 10% off. 10% is nice of course. The code was V185. I looked around on the Internet whether I could find any other codes. I could, but they were all outdated. One thing struck me though, they where all of the form Vxxx, where xxx denotes a number.

So in theory you could jus go to the form and try all numbers between 100 and 999 and see which one would give you the biggest discount. I tried a few and it seems that there was something to this theory. Sometimes it said invalid code, but often it said something like, code not valid for this date or code not valid for this region. Hmm, what could try 900 codes without getting bored?

So I fired up my python editor and wrote a small script. This turned out to be slightly more complicated than thought – the site needed a cookie and stored in the cookie some of the route information. Weird. Also it, seemed to generate the form on the fly based on I don't know what. But I had my little firefox developer toolbar, converted the post form to get, looked at the cookies I had and pasted it all in my Python script and after 20 minutes or so it actually worked. I added a sleep statement to the script to not send out all queries at once (I'm trying to get a discount here, not to annoy the server) and let the script run for another 20 minutes.

Result: It is not just V185 that gives you 10% off. V311 also gives you 10% off! Oh well, at least now I know for sure.