Get site image pages all together

Daniel Asher Resnick 11 months ago
parent b7674c1a47
commit 86b1c16b5d
  1. 40
      wiki-map.pl

@ -353,6 +353,7 @@ my $site_query_results = $mw->api
inprop => 'url',
} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details};
my %site_icon_pages;
foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
{
next if $site_page_ref->{title} =~ /^Category:/;
@ -372,14 +373,17 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
next;
}
my $imageinfo_query_results = $mw->api({ action => 'query',
prop => 'imageinfo',
titles => "File:$parsed_template->{named_params}{icon}",
iiprop => 'url'
}) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details};
my %image_pages = %{$imageinfo_query_results->{query}{pages}};
my $image_url = (values %image_pages)[0]{imageinfo}[0]{url};
$grid->add_image(HexGrid::to_id($parsed_template->{named_params}{icon}), $image_url);
$site_icon_pages{"File:$parsed_template->{named_params}{icon}"} =
$parsed_template->{named_params}{icon};
# my $imageinfo_query_results = $mw->api({ action => 'query',
# prop => 'imageinfo',
# titles => "File:$parsed_template->{named_params}{icon}",
# iiprop => 'url'
# }) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details};
# my %image_pages = %{$imageinfo_query_results->{query}{pages}};
# my $image_url = (values %image_pages)[0]{imageinfo}[0]{url};
# $grid->add_image(HexGrid::to_id($parsed_template->{named_params}{icon}), $image_url);
my $pin = HexGrid::Pin->new
(
@ -393,6 +397,26 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
$tile->pin($pin);
}
say STDERR "Getting Site icon image pages";
my $site_icon_query_results = $mw->api({ action => 'query',
prop => 'imageinfo',
titles => join('|', keys %site_icon_pages),
iiprop => 'url'
}) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details};
foreach my $page (values %{$site_icon_query_results->{query}{pages}})
{
if($page->{imageinfo})
{
say STDERR "Processing image: $page->{title}";
$grid->add_image
(
HexGrid::to_id($site_icon_pages{$page->{title}}),
$page->{imageinfo}[0]{url}
);
}
}
# Render and output
open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!";
say $fh ($html_document ? wrap_in_html($grid) : $grid->render);

Loading…
Cancel
Save