From 86b1c16b5dd71526c344ea520ad12788e13d4231 Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Sat, 6 Jan 2024 18:46:29 -0600 Subject: [PATCH] Get site image pages all together --- wiki-map.pl | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/wiki-map.pl b/wiki-map.pl index caac4bf..44a78c3 100644 --- a/wiki-map.pl +++ b/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);