#!/usr/bin/perl # Copyright 2009 Thomas Lotze # This script is licensed under a Creative Commons Attribution 3.0 license; you can use it and modify it, # so long as you provide an attribution link to thomaslotze.com See http://creativecommons.org/licenses/by/3.0/ use strict; use warnings; $|=1; # autoflush output buffers use Getopt::Long; my $verbose = 0; # option variable with default value (0) my $help=0; GetOptions ('verbose' => \$verbose, 'help'=>\$help); # read in api key, username, and password from command-line my ($apiKey, $txtUser, $txtPass)=@ARGV; use HTTP::Request::Common(qw(POST)); use HTTP::Cookies; use LWP::UserAgent; use WWW::Mechanize; use Mail::Sendmail 0.75; use MIME::QuotedPrint; use HTML::Entities; use HTTP::Date('time2iso'); # Read in current sets from file my %currentSetsHash=(); my $localFile="currentSets.txt"; if (-e $localFile) { open SETS, $localFile; while (defined(my $line=)) { chomp($line); $currentSetsHash{$line}=1; } close SETS; } my @newSets=(); # Get the gatherer website and see what the list of sets is; keep track of any new ones my $mech = WWW::Mechanize->new( agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)' ); $mech->agent_alias('Windows Mozilla'); push @{ $mech->requests_redirectable }, 'POST', 'GET'; my $cookie_jar=HTTP::Cookies->new(); $mech->cookie_jar($cookie_jar); my $gathererSite="http://gatherer.wizards.com/Pages/Default.aspx"; $mech->get($gathererSite); my $content = $mech->content(); my @lines=split(/\n/,$content); my $inSetsList=0; foreach my $line (@lines) { if ($line =~ /id="ctl00_ctl00_MainContent_Content_SearchControls_setAddText"/) { $inSetsList=1; } if ($inSetsList) { if ($line =~ /