I’m a huge sci-fi fan (big surprise there) but can’t seem to be able to keep up with TV schedules that well. Particularly because I tend to save up TV over a week (or more) and then catch up later. Which means I either need to set the DVR or remember to source content from elsewhere. I used to literally write episode airings on a paper calendar, but that got annoying to keep up with and then I’d spill coffee on it or lose it. Yes, yes, I know the DVR can do recurring recordings, but I tend to lose track after a few weeks and then wonder what’s new, what’s a rerun, or what aired during a huge thunderstorm and we either lost signal or got preempted by weather coverage.
I thought about email reminders, but that gets spammy and doesn’t really fit my requirements. Local calendars wouldn’t really work, as I often move between computers and don’t want to fool with exporting/importing. Not to mention others would like to access the schedule. But the Google based calendar would be cumbersome and entirely too time consuming for this purpose. A text file hosted on my XS would be perfect.
Eventually what I figured out I wanted was to create a personalized TV schedule in a flat text file in a data format that awk could parse.
OK, easy enough. I looked up schedules on Wikipedia and did up something that looks like this (obviously this is a truncated version):
2011/06/20:Sanctuary:S03E20:”Into the Black”
2011/06/23:Futurama:S06E14:”Neutopia”
2011/06/23:Futurama:S06E15:”Benderama”
2011/06/30:Futurama:S06E16:”Ghost in the Machines”
2011/07/07:Futurama:S06E17:”Law and Oracle”
2011/07/08:Torchwood:S04E01:”The New World”
2011/07/11:Alphas:S01E01:”Pilot”
2011/07/11:Eureka:S04E11:”Liftoff”
2011/07/11:Warehouse.13:S03E01:”The New Guy”
2011/07/14:Futurama:S06E18:”The Silence of the Clamps”
2011/07/15:Haven:S02E01:”A Tale of Two Audreys”
2011/07/15:Torchwood:S04E02:”Renditions”
2011/07/17:Breaking.Bad:S04E01:”Box Cutter”
Yeah, I manually entered all that, but sorting stuff before editing, depending on what I’m doing, makes data entry a breeze.
To sort by date:
cp tv-listings.txt tv-listings.bak
sort tv-listings.bak > tv-listings.txt
To sort by show name:
cp tv-listings.txt tv-listings.bak
sort -t: -k2 tv-listings.bak > tv-listings.txt
Now, sorted by date would probably be good enough. But I wanted something a little more human readable. Enter awk.
Since the XS has Apache, it would be nice for my friends and me to be able to access my TV schedule from anywhere. I’m not gonna mess around with html, though. A simple .txt is fine.
The difficult part was figuring out how to make awk parse the date. To generate a text file that looks like this and upload it to my XS…
Jun 20 Mon Sanctuary S03E20 “Into the Black”
Jun 23 Thu Futurama S06E14 “Neutopia”
Jun 23 Thu Futurama S06E15 “Benderama”
Jun 30 Thu Futurama S06E16 “Ghost in the Machines”
Jul 07 Thu Futurama S06E17 “Law and Oracle”
Jul 08 Fri Torchwood S04E01 “The New World”
Jul 11 Mon Alphas S01E01 “Pilot”
Jul 11 Mon Eureka S04E11 “Liftoff”
Jul 11 Mon Warehouse.13 S03E01 “The New Guy”
Jul 14 Thu Futurama S06E18 “The Silence of the Clamps”
Jul 15 Fri Haven S02E01 “A Tale of Two Audreys”
Jul 15 Fri Torchwood S04E02 “Renditions”
Jul 17 Sun Breaking.Bad S04E01 “Box Cutter”
…here’s the simple bash script I used:
#!/bin/bash
FILE=tv-listings.txt
# Backup master tv listings file just in case
cp $FILE $FILE.bak
sort $FILE.bak > $FILE
awk ‘BEGIN{FS=”:”}
{
cmd=”date +”%b %d %a” –date= 47″$1″