20090530

Wget this

I think I've mentioned before my netflix obsession: I want to be able to receive a disk from my selected set of movies without knowing what's on it till I start to watch it.

Well, this system works fine, but occasionally I do at least want to know how long this weeks movie is, and maybe even what genre it's in. This is trick, because there's no easy way to do this on the netflix site without learning the identity of the movie. So I decided to hack together a system to do this.

I could have tried to figure out how to use the netflix API to do this, but all that authentication stuff seems complicated. So instead, I decided to hack together something via feedflix: this is a third part site that shows you statistics about your usage. After logging in, it shows you a link to your current movie. So if I could just get a bot to simulate logging in and clicking on the movie, then I could scrape out the relevant details. Well, of course, it was much more complicated than I had thought. As well as dealing with cookies and session keys and the like, there was one particularly nasty bit: the site would return an authentication code which you had to post back with the log in form. Mostly this form is randomly chosen letters and numbers. But sometimes it would return a string with other characters like + in, which seemed to cause a problem when I would post them back. So I had to borrow someone else's trick, and run perl on the string to URL encode it. As a result, I think that this is quite possibly the nastiest little shell script that I have ever concocted. I'll paste it in, mainly to offend people who have any clue that it means:


#!/bin/bash
EMAIL={my email address}
PWD={my feedflix password}
WOPTS="--cookies=on --load-cookies cookies.txt --keep-session-cookies --save-cookies cookies.txt -olog"
BASEURL=http://feedflix.com
LOGIN=/login/
TMPFILE=movie

rm cookies.txt
wget -O$TMPFILE $WOPTS $BASEURL$LOGIN
AUTH1=$(grep authenticity $TMPFILE | cut -d\" -f12)
AUTH=$(perl -MURI::Escape -e "print uri_escape('$AUTH1');")
echo $AUTH
wget $BASEURL$LOGIN $WOPTS --post-data=authenticity_token=$AUTH\&email=$EMAIL\&password=$PWD\&commit=Login -O$TMPFILE
MOVIE=$(grep "href=/movie" $TMPFILE | head -n1 | cut '-d=' -f2 | cut '-d>' -f1 )
wget -O$TMPFILE $WOPTS $BASEURL$MOVIE
grep Duration movie -A 1 | tail -n1
grep Genre movie -A 1 | grep -v div
rm $TMPFILE


Vile, huh? And it'll probably break on the next movie that comes through, so I'll have to figure a way to patch it up then.

20090513

Chip Chop

Getting back to my office with some sesame chicken and rice, I noticed that the pair of chopsticks I had picked up was deficient to the tune of one. I didn't really feel like going back to the canteen to get another one, so scouted around my desk for an alternative. I found a plastic knife, which I used with my one chopstick to make an ad hoc pair of chopsticks. Result? It's actually easier to eat rice with one chopstick and a plastic knife than it is with a pair of chopsticks. Good to know.

20090511

Stamp Duty

I thought that I had already posted a lengthy and tedious whinge about the cost of stamps which I could link to, but it looks like I didn't so I'll have to recreate it on the fly.

A while ago, I found a letter that I had sent returned to me with a little "returned for postage" sticker placed on it. "Returned for postage"? What on earth does that mean? It had a first class stamp on it, which had been franked. I shrugged, put the letter in a new envelope with a fresh stamp, and stuck it back in the mail.

Of course, exactly the same thing happened. And so I went to my local post office, and asked them to explain what this meant. The clerk helpfully explained that the price of a first class stamp had gone up from 41c to 42c. "So what?" I asked "This stamp just says "First class", so it should be good for a first class letter. Apparently not. The stamp I had, which looked like:

is apparently only worth 41c, though there's nothing on it to indicate this.

I then paid the extra 1c of postage, which apparently was enough (and got a receipt for it), and my letter was taken away to be delivered. But now I had a big roll of what I thought were first class stamps but which turned out to be merely 41c stamps in a 42c world. So I bought 100 1c stamps, and proceeded to stick them on every letter that I send (the clerk eyed me when I asked for 100 1c stamps, as if to say "are you sure?" -- well, it's only a dollar for me).

This was just a few months back, but on the news today I heard some earthshattering news... the price of a first class stamp has now gone up to 44c. Oh, great. Now I need to stick 1 41c stamp and THREE 1c stamps to get my letters delivered. Damn you, USPS! Damn you! I was fooled into believing that you had sold me some mystical "forever" stamps, but it turns out you got me good and proper. Well, the jokes on you, since these 1c stamps must cost way more than 1c each to produce and process.

Puzzled by all this confusing stamp price palava? Then maybe this website is for you.