Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions IFComp/script/populate_ifdb_ids.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,38 @@
use Path::Class;
use LWP;
use Readonly;
use Getopt::Long;

use lib "$FindBin::Bin/../lib";
use IFComp::Schema;

use XML::LibXML;

use open ':std', ':encoding(UTF-8)';

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(
agent => 'IFComp populate_ifdb_ids/1.0 (+https://ifcomp.org)', );

my $ifdb_url = "https://ifdb.org";

Expand All @@ -38,10 +51,16 @@
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";

Expand Down Expand Up @@ -86,6 +105,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;
Expand All @@ -104,4 +132,3 @@ sub entry_for_tuid {
"*** WARNING: Couldn't find an IFDB ID for $title ($entry_id).\n";
}
}

Loading