From bb1f374f6980c0af0bc234272a86e53e1217d0f6 Mon Sep 17 00:00:00 2001 From: silverwizard Date: Sun, 13 Dec 2020 03:06:55 +0000 Subject: [PATCH] Upload files to '' Added wiki parser to create new KML file automatically. --- makekml.pl | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 makekml.pl diff --git a/makekml.pl b/makekml.pl new file mode 100644 index 0000000..9ee6634 --- /dev/null +++ b/makekml.pl @@ -0,0 +1,79 @@ +use MediaWiki::API; +use Switch; +use strict; +use URI::Escape; +use Geo::KML; + +my $filename = 'ours.kml'; +my $out = &create_styles; +my $kml = Geo::KML->new(version => '2.2.0'); + +my $mw = MediaWiki::API->new(); +$mw->{config}->{api_url} = 'https://jackpoint.obscuritus.ca/api.php'; + +my $articles = $mw->list ( { + action => 'query', + list => 'categorymembers', + cmtitle => 'Category:Locations', + cmlimit => 'max' } ) + || die $mw->{error}->{code} . ': ' . $mw->{error}->{details}; + +foreach (@{$articles}) { + my $name = $_->{title}; + my $lat; + my $long; + my $desc; + my $page = $mw->get_page( { title => $name } ); + if($page->{'*'} =~ m/.*Template:Location.*/){ + my @locs = split /\|/ , $&; + foreach(@locs) { + my @tokens = split(/=/, $_); + switch($tokens[0]) { + case "Latitude" { $lat = $tokens[1] } + case "Longitude" { $long = $tokens[1] } + case "Notes" { $desc = $tokens[1] } + } + } + } + my $coord = $long . ',' . $lat; + if( $lat && $long){ + push(@{$out->{Document}->{AbstractFeatureGroup}}, append_placemark($name, $desc, $coord)); + } +} +$kml->writeKML($out, $filename); + + +sub append_placemark { + my($name, $desc, $coord) = @_; + return + { + Placemark => + { + Point => + { + coordinates => $coord, + }, + styleUrl =>'#jackpoint-logo', + name => "$name", + description => $desc + } + }; +} + +sub create_styles { + + return + { + Document => { + AbstractStyleSelectorGroup => [ + { + Style => { + IconStyle => { Icon => { href => 'https://jackpoint.obscuritus.ca/images/logo.jpg' }, }, + LabelStyle => { scale => '0' }, + id => 'jackpoint-logo' + } + } + ], + } + }; +}