rivviepop phantom


the SJ Sharks hockey schedule on your phone

Posted in Cellphones, Scripting by rivviepop on the 2006-10-01

Admit it, you like hockey. However, the most difficult thing to remember is when the games are - with 90-ish of them spread over what, 8 months(?) - how could you possibly be expected to keep your act together along with work and everything else.

One thing you usually have is your cellphone, and almost every modern phone has a Calendar application that can somehow be synchronized with your desktop or online. I think you can see where this is going…

As covered in a previous post, I use Mobical to sync my contacts, calendar and notes. Mobical allows you to export and import in vCal (and ICS) format; the SJ Sharks website allows you to download the schedule in what they call “Outlook” format - it’s a standard tab-delimited text file though, there’s nothing really Outlook specific about it. So, all we need to do is convert the text file into vCal format.

Today I whipped up a little awk script you can use to create the vCal import file; save the below code as “sharks_vcal.awk” and then use it from a bash command line in a manner like so:

cat sharks_schedule_2006_2007.txt | awk -f sharks_vcal.awk > sharks_schedule_2006_2007.vcs

Note: the timestamps below are converted to UTC; Mobical will operate on GMT +2 (Sweden, where they’re located) standard if the timestamps are left in ‘local’ (non-UTC) format.

sharks_vcal.awk


# Convert the Sharks "Outlook" (tab delimited) format to vCal format
# http://www.sjsharks.com/schedule/outlook.asp

# set our file separator to TAB, print out the vCal header
BEGIN {
  FS = "[t]";
  print "BEGIN:VCALENDAR";
  print "VERSION:1.0";
}

# Make a vCal UTC format out of the ugly Sharks format
# ex.: 10/5/2006 7:30:00 PM -> 20061006T023000Z
# m/d/y, h:m:s am|pm
function vCalDTS(date,time)
{
  # date reorg for mktime()
  split(date,adate,"/");
  d_ts = sprintf("%d %02d %02d",adate[3],adate[1],adate[2]);

  # time reorg for mktime()
  split(time,time1," ");
  split(time1[1],time2,":");
  hour = sprintf("%02d",time2[1]);
  #
  # do a little 12->24 hour time voodoo
  if ((tolower(time1[2]) ~ /pm/) && (hour !~ /12/))
    hour = hour + 12;
  else if ((hour ~ /12/) && (tolower(time1[2]) ~ /am/))
    hour = hour - 12;
  t_ts = sprintf("%02d %02d %02d",hour,time2[2],time2[3]);

  # make UTC time
  e_ts = mktime(d_ts " " t_ts " -");

  # add the GMT offset, accounting for daylight savings time
  # (will always be -0700 or -0800 for the Sharks schedule)
  if (tz ~ /-0700/)
    e_ts = e_ts + 25200;
  else
    e_ts = e_ts + 28800;

  # return vCal friendly format
  return (strftime("%Y%m%dT%H%M%SZ",e_ts));
}

{
  # skip the first line with column headers
  if ($1 ~ /Subject/)
    next;

  # print the easy stuff
  print "BEGIN:VEVENT";
  printf("DTSTART:%sn",vCalDTS($2,$3));
  printf("DTEND:%sn",vCalDTS($4,$5));
  printf("SUMMARY:%sn",$1);

  # home vs. away games
  if (match($1," at "))
    printf("LOCATION:%sn",substr($1,RSTART+RLENGTH));
  else
    print "LOCATION:Shark Tank";

  # print the rest of the easy stuff
  lm_dts = strftime("%Y%m%dT%H%M%S",systime());
  print "LAST-MODIFIED:" lm_dts;
  print "CLASS:PUBLIC";
  print "END:VEVENT";
}

# print out the final vCal footer
END {
  print "END:VCALENDAR";
}

I should note that in the file I downloaded from the SJ Sharks website, there was a mistake on the ending time on the 2007-03-04 game (Sharks at Dallas); they inserted the 24-hour time instead of the 12-hour time used elsewhere.

If you don’t want to be worried with running a script and feeling nerdy, don’t fret - you can download the vCal import file I created from Rapidshare.de. Unzip the file, import it into your program of choice, and sync to your phone.

sharks_schedule_2006_2007_vcs.zip

One Response to 'the SJ Sharks hockey schedule on your phone'

Subscribe to comments with RSS or TrackBack to 'the SJ Sharks hockey schedule on your phone'.


  1. on 2007-01-13 on 13:24

    [...] to work with; you can download vCards, upload iCals, whatever! Here’s one thing I did with it: the SJ Sharks hockey schedule on your phone « rivviepop phantom Alas, the SyncBerry client has no demo — it’s setup is basically the same, but more confusing [...]

Leave a Reply

You must be logged in to post a comment.