#!/usr/bin/perl # author: Orion Montoya # Copyright 2008 Orion Montoya; dual-licensed under {GPLv3 or later} or {CC BY-SA}. # met-parsepages.pl #use JSON; #use Date::Calc qw(Decode_Date_US Date_to_Time); use Date::Manip; =how This assumes that you've downloaded the Met's day-of-the-week subscription pages to your local disk; no point in using LWP if the data never changes. met-parsepages.pl *.html > mosh.html grab all tables with class=series_perf_table, and all

s. then grab: -h2 contents, stripped of leading & trailing whitespace; - Don Giovanni - Friday, October 10, 2008 - 8:00 PM ser_name, perf_name, url, perf date, perf_time populate a hash: %series = ( $ser_name => { $perf_name => { url => $url, date => $date , time => $time }, }} then print as JSON or HTML =cut undef $/; # grab whole file at once my %series; my %shows; while (<>) { my (@ser_name, @table); @ser_name = $_ =~ m/

\s*(.*?)\s*<\/h2>/msg; @table = $_ =~ m//msg; if ($#table != $#ser_name) { die "input has changed: different numbers of tables, $#table, and series, $#ser_name"; } else { # print "tables, $#table, and series, $#ser_name\n"; } for (my $i = 0; $i < scalar(@ser_name); $i++) { # - # - # - @td = $table[$i] =~ m/.*?<\/tr>/msg; foreach my $t (@td) { $t =~ m!!gsm; my $url = $1; my $perf_name = $2; $perf_name =~ s/ *$//; $shows{$perf_name}++; $t =~ m!!gsm; my $date = $1; $t =~ m!!gsm; my $time = $1; $series{$ser_name[$i]}{$perf_name} = { 'u' => $url, 'd' => $date, 't' => $time }; } } } print '

Met Opera Subscription Helper

Not affiliated with the Metropolitan Opera

Check the boxes for the operas you want to see in the 2008/09 Metropolitan Opera season. The table will sort to show you which series have the most matches for your selections, and how many exchanges/single tickets you would need to buy to see all the shows you want to see. This listing contains only performances that are part of a subscription series: no Gala Events, no Ring Cycle. Within the subscription table, hover over a show\'s title to see its date and time.

'; foreach my $show (sort(keys(%shows))) { print "
$show
\n"; } print "
Clear all selections
\n"; print '


Don Giovanni Friday, October 10, 20088:00 PM
([^<,]+)([^<]*) ?(.*?)(.*?)
'; foreach my $ser (sort(keys(%series))) { print " \n"; } print '
seriesshowsscoreexchange/single
$ser "; foreach my $perf (sort { UnixDate(ParseDate($series{$ser}{$a}{'d'}), "%s") <=> UnixDate(ParseDate($series{$ser}{$b}{'d'}), "%s") } (keys(%{$series{$ser}}))) { print "$perf, "; } print " 0 0

Comments, etc. to orion@ this domain.

If you like this tool, and still have money to burn after buying your subscription, you could

a couple of bucks or get me something from my My Amazon.com Wish List

Copyright 2008 Orion Montoya; distributed under a Creative Commons Attribution-Share Alike license.
JQuery and tablesorter made this very easy.
Perl source that generated this page.

'; # print objToJson({%series}, {pretty => 1, indent => 2});