ASPENSMONSTER Just another WordPress site

August 4, 2011

Shell Scripting for Pottermore

Filed under: Uncategorized — aspensmonster @ 6:30 pm

Flattr this!

I’m a Harry Potter nut. Or rather, I have a love-hate relationship with a series that I felt started off great, but then went sour. But that hasn’t stifled the fever in the slightest. Pottermore is the latest trend that J.K. Rowling (and Sony) have rolled out. Billed as an online e-book experience with touches of interactivity, it’s put all of us Potter heads into a frenzy. However, when they started opening up registration slots five days ago via their “magical quill” clue promotion, the release times were all in the morning, British Summer Time. Which is fine if you live near the Meridian. I don’t. 9AM BST translates to too-fucking-early AM here in Texas.

However we were informed that the clues would be numerical. For example: “How many people competed in the Triwizard Tournament in the Goblet of Fire? Multiply by 28”. The URL that would lead to the quill/clue would then be of the form

http://quill.pottermore.com/$number

So I crafted a script that would detect when registration was open, then send me an email so I could see the clue and run another script if necessary to get the URL.

#!/bin/bash

while [ 1 -le 2 ]

do
        GET pottermore.com | grep 'Sorry, Day 3 registration is now closed'
        if [ $? -ne 0 ]
        then
                sendEmail -f USER@DOMAIN.TLD -t USER@DOMAIN.TLD -u ['Registration is OPEN!'] -m [Reg open.] -s MAIL.DOMAIN.TLD
        fi
sleep 15s
done

In a nutshell, it checks to see if the website has been updated from the previous day or not.

Lucky for me, the folks at Pottermore decided to have day four registration occur at a slightly more sane time for us folks in the states. I got an alert on my phone whilst in the shower. Staggering out five minutes later, I noticed it was an email stating that “Registration is OPEN!” So naturally I ran back to my machine and investigated. The clue was dead obvious to anyone who had read the books and so my second script wasn’t necessary. But for posterity’s sake, here it is:

#!/bin/bash

while [ 1 -le 2 ]

do

for ((i=1;i < 2001; i++))
do
        GET quill.pottermore.com/$i | grep '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Pottermore: a unique online Harry Potter experience from J.K. Rowling</title>'
        if [ $? -ne 0 ]
        then
                echo quill.pottermore.com/$i >> out2.txt
                sendEmail -f USER@DOMAIN.TLD -t USER@DOMAIN.TLD -u ['Latest pottermore URL'] -m [quill.pottermore.com/$i] -s MAIL.DOMAIN.TLD
        fi
done
sleep 5m
done

In a nutshell, it constantly scrapes the possible URLs and, if the resulting page is the “try again” one (really, if you get the wrong number, it just redirects to the pottermore.com page), do nothing. Else, send an email.

The clue led to a Sony page dedicated to blu-ray players and videogame hand helds, all sporting Deathly Hallows adverts. A quick scan of its source code yielded no hints (but some rather humorous comments from the web developers). So I then tried searching for “quill” in their search bar. Apparently, tens of thousands of others thought to do the same thing, and appropximately 15 minutes after opening, the Sony page that quill.pottermore.com/112 redirected to was ISE’ing. At which point, the redirect was instead updated to redirect to:

http://www.pottermore.com/en/magical-quill/found

At which point I could provide my info and eagerly await further instructions. Incidentally, knowing the form of the “found” URL could greatly simplify the above scripts. But I don’t need to at this point, since I’m registered 😀