Created
September 15, 2012 16:45
-
-
Save andrewrjones/3728775 to your computer and use it in GitHub Desktop.
Lets me know when Arsenal tickets are available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use v5.10.1; | |
use strict; | |
use warnings; | |
use Getopt::Long; | |
use Storable qw(store retrieve); | |
use Email::Sender::Simple qw(sendmail); | |
use Email::Simple; | |
use Email::Simple::Creator; | |
use aliased 'WWW::ArsenalFC::TicketInformation'; | |
use aliased 'WWW::ArsenalFC::TicketInformation::Match'; | |
use aliased 'WWW::ArsenalFC::TicketInformation::Match::Availability'; | |
use aliased 'WWW::ArsenalFC::TicketInformation::Category'; | |
use constant NOTIFIED_FILE => 'notified.store'; | |
# memberships we care about | |
use constant MEMBERSHIPS => [ Availability->GENERAL_SALE, Availability->RED ]; | |
# get options | |
my $from; | |
my $to; | |
GetOptions( 'from=s' => \$from, 'to=s' => \$to ); | |
die "no from address" unless $from; | |
die "no to address" unless $to; | |
my $notified = (); | |
if ( -e NOTIFIED_FILE ) { | |
$notified = retrieve(NOTIFIED_FILE) or die "could not load file: $@"; | |
} | |
my $ticket_info = TicketInformation->new(); | |
$ticket_info->fetch(); | |
die "could not get any matches!" unless $ticket_info->matches; | |
for my $match ( @{ $ticket_info->matches } ) { | |
# can only go to home matches | |
next unless $match->is_home; | |
next unless $match->availability; | |
for my $availability ( @{ $match->availability } ) { | |
next unless $availability->memberships; | |
next unless $availability->type == $availability->FOR_SALE; | |
for my $membership ( @{ $availability->memberships } ) { | |
for my $our_membership ( @{ +MEMBERSHIPS } ) { | |
if ( $our_membership == $membership ) { | |
my $key = $match->fixture . $match->datetime_string; | |
unless ( $notified->{$membership} | |
&& $notified->{$membership}->{$key} ) | |
{ | |
send_email( $match->fixture, $match->datetime_string ); | |
$notified->{$membership}->{$key} = 1; | |
} | |
} | |
} | |
} | |
} | |
} | |
# save back | |
store( $notified, NOTIFIED_FILE ); | |
sub send_email { | |
my ( $fixture, $when ) = @_; | |
my $email = Email::Simple->create( | |
header => [ | |
To => $to, | |
From => $from, | |
Subject => "Tickets availables for $fixture on $when", | |
], | |
body => "See http://www.arsenal.com/membership/buy-tickets for more.\n", | |
); | |
sendmail($email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment