You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
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'
|
|
}
|
|
}
|
|
],
|
|
}
|
|
};
|
|
}
|
|
|