From 33a1867641119ab2106f14d976f6fb404369de9a Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Thu, 28 Dec 2023 14:36:41 -0600 Subject: [PATCH] Fetch paths from wiki --- wiki-map.pl | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/wiki-map.pl b/wiki-map.pl index 3b2e13a..9c754b6 100644 --- a/wiki-map.pl +++ b/wiki-map.pl @@ -24,6 +24,7 @@ my $region_template_name = "MapRegion"; my $subregion_template_name = "MapSubregion"; my $location_template_name = "MapLocation"; my $site_template_name = "MapSite"; +my $path_template_name = "MapPath"; my $border_width = 1; my $border_colour = 'black'; @@ -299,6 +300,67 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) $grid->get_tile_at($nw, $sw)->pin($pin); } +my (%path_specs); +say STDERR "Getting Path pages"; +my $path_query_results = $mw->api +( { + action => 'query', + generator => 'categorymembers', + prop => 'info|revisions', + gcmtitle => 'Category:Paths', + gcmlimit => 'max', + rvprop => 'content', + inprop => 'url', +} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; + +foreach my $path_page_ref (values %{$path_query_results->{query}{pages}}) +{ + next if $path_page_ref->{title} =~ /^Category:/; + my $path_name = $path_page_ref->{title}; + + say STDERR "Processing Path $path_name"; + + my $path_url = $path_page_ref->{canonicalurl}; + my $path_content = $path_page_ref->{revisions}[0]{'*'}; + my $parsed_template = MWTemplate::Parse($path_content, $path_template_name); + next unless $parsed_template; + + $path_specs{$path_name} = + { + id => "$path_name-path", + tile_page => "$path_name/Tiles", + colour => $parsed_template->{named_params}{colour}, + stroke_width => $parsed_template->{named_params}{stroke_width} + }; +} + + + + +say STDERR "Getting Path Tile pages"; +my $path_tile_query_results = $mw->api +( { + action => 'query', + titles => join('|', map { $_->{tile_page} } values %path_specs), + prop => 'revisions', + rvprop => 'content', +} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; + +foreach my $page (values %{$path_tile_query_results->{query}{pages}}) +{ + my $content = $page->{revisions}[0]{'*'}; + my ($path_name) = $page->{title} =~ /(.*)\/Tiles/; + say STDERR "Processing tiles for: $path_name"; + my %path_spec = %{$path_specs{$path_name}}; + my @path_coords; + foreach my $coords (split /;/, $content) + { + do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex; + push @path_coords, [$1,$2]; + } + $grid->make_path_from($path_spec{id}, \@path_coords, css_class => 'path', + colour => $path_spec{colour}, style => { 'stroke-width' => $path_spec{stroke_width} }); +} open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!";