Upload files to ''

Added wiki parser to create new KML file automatically.
main
silverwizard 4 years ago
parent 870f085ff6
commit bb1f374f69
  1. 79
      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 => "<a href=\"https://jackpoint.obscuritus.ca/index.php?title=" . uri_escape($name) . "\">$name</a>",
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'
}
}
],
}
};
}
Loading…
Cancel
Save