From cac4ea5233307b9e89c957e1a77fcc81ddd47bd5 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Tue, 1 Sep 2026 15:26:41 -0700 Subject: [PATCH 1/2] Add `--ifdb-only` mode to `populate_ifdb_ids.pl` Allows testing IFDB lookups for a given year without connecting to the production IFComp database or updating entry records. --- IFComp/script/populate_ifdb_ids.pl | 49 ++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/IFComp/script/populate_ifdb_ids.pl b/IFComp/script/populate_ifdb_ids.pl index 6a2d8b38..a1553ff8 100755 --- a/IFComp/script/populate_ifdb_ids.pl +++ b/IFComp/script/populate_ifdb_ids.pl @@ -9,9 +9,9 @@ use Path::Class; use LWP; use Readonly; +use Getopt::Long; use lib "$FindBin::Bin/../lib"; -use IFComp::Schema; use XML::LibXML; @@ -19,15 +19,29 @@ Readonly my $PAUSE_BETWEEN_QUERIES => 1; -my $schema = IFComp::Schema->connect( 'dbi:mysql:ifcomp', - 'root', '', { mysql_enable_utf8 => 1 } ); -$schema->entry_directory( Path::Class::Dir->new("$FindBin::Bin/../entries") ); +my $ifdb_only_year; +GetOptions( 'ifdb-only=i' => \$ifdb_only_year ) + or die "Usage: $0 [--ifdb-only=YEAR]\n"; -my $current_comp = $schema->resultset('Comp')->current_comp; +my ( $year, $current_comp, $schema ); -my $ua = LWP::UserAgent->new; +if ($ifdb_only_year) { + $year = $ifdb_only_year; + warn "IFDB-only mode: skipping database; using year $year\n"; +} +else { + require IFComp::Schema; + $schema = IFComp::Schema->connect( + 'dbi:mysql:ifcomp', + 'root', '', + { mysql_enable_utf8 => 1 } + ); + $schema->entry_directory( Path::Class::Dir->new("$FindBin::Bin/../entries") ); + $current_comp = $schema->resultset('Comp')->current_comp; + $year = $current_comp->year; +} -my $year = $current_comp->year; +my $ua = LWP::UserAgent->new; my $ifdb_url = "https://ifdb.org"; @@ -38,10 +52,17 @@ my $competition_search_year_uri = "$ifdb_url/search?comp&searchfor=$year%20series%3AAnnual+Interactive+Fiction+Competition&xml"; -my $competition_tuid = @{ XML::LibXML->load_xml( +my @competition_tuids = map { $_->textContent } @{ + XML::LibXML->load_xml( string => $ua->get($competition_search_year_uri)->content )->getElementsByTagName("tuid") -}[0]->textContent; +}; + +if ( !@competition_tuids ) { + die "No IFDB competition found for year $year\n"; +} + +my $competition_tuid = $competition_tuids[0]; print "competition_tuid: $competition_tuid\n\n"; @@ -86,6 +107,15 @@ sub entry_for_tuid { my %entries = map { entry_for_tuid($_) => $_ } @tuids; +if ($ifdb_only_year) { + warn "IFDB-only mode: found " + . scalar( keys %entries ) + . " ballot links for " + . scalar(@tuids) + . " IFDB games; skipping database updates.\n"; + exit 0; +} + for my $entry ( $current_comp->entries ) { next unless $entry->is_qualified; @@ -104,4 +134,3 @@ sub entry_for_tuid { "*** WARNING: Couldn't find an IFDB ID for $title ($entry_id).\n"; } } - From b933c3570e29acb0c2508c96764a76d24c863070 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Tue, 1 Sep 2026 15:26:44 -0700 Subject: [PATCH 2/2] Set custom `User-Agent` for IFDB requests in `populate_ifdb_ids.pl` IFDB sits behind Cloudflare, which rejects the default `libwww-perl` User-Agent with error 1010. --- IFComp/script/populate_ifdb_ids.pl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/IFComp/script/populate_ifdb_ids.pl b/IFComp/script/populate_ifdb_ids.pl index a1553ff8..18a9ea2d 100755 --- a/IFComp/script/populate_ifdb_ids.pl +++ b/IFComp/script/populate_ifdb_ids.pl @@ -31,17 +31,16 @@ } else { require IFComp::Schema; - $schema = IFComp::Schema->connect( - 'dbi:mysql:ifcomp', - 'root', '', - { mysql_enable_utf8 => 1 } - ); - $schema->entry_directory( Path::Class::Dir->new("$FindBin::Bin/../entries") ); + $schema = IFComp::Schema->connect( 'dbi:mysql:ifcomp', 'root', '', + { mysql_enable_utf8 => 1 } ); + $schema->entry_directory( + Path::Class::Dir->new("$FindBin::Bin/../entries") ); $current_comp = $schema->resultset('Comp')->current_comp; - $year = $current_comp->year; + $year = $current_comp->year; } -my $ua = LWP::UserAgent->new; +my $ua = LWP::UserAgent->new( + agent => 'IFComp populate_ifdb_ids/1.0 (+https://ifcomp.org)', ); my $ifdb_url = "https://ifdb.org"; @@ -52,8 +51,7 @@ my $competition_search_year_uri = "$ifdb_url/search?comp&searchfor=$year%20series%3AAnnual+Interactive+Fiction+Competition&xml"; -my @competition_tuids = map { $_->textContent } @{ - XML::LibXML->load_xml( +my @competition_tuids = map { $_->textContent } @{ XML::LibXML->load_xml( string => $ua->get($competition_search_year_uri)->content )->getElementsByTagName("tuid") };