Created
March 6, 2016 00:06
-
-
Save lukec/9a2ec88f46bcb97a8d29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use XML::Simple; | |
# USAGE: cat your-file.kml | perl art-kml-to-csv > your-file.csv | |
# | |
# This script reads from standard input and writes to standard output. | |
# Pipe your file into this script | |
my $xml = XMLin(join '', <STDIN>); | |
print "TITLE, NAME, URL, GEO\n"; | |
my $placemarks = $xml->{Document}{Folder}{Placemark}; | |
for my $k (keys %$placemarks) { | |
my $p = $placemarks->{$k}; | |
# Grab the data attributes of this placemark | |
my $data = $p->{ExtendedData}{SchemaData}{SimpleData} // {}; | |
my $name = $data->{NAME}{content} // ''; | |
my $title = $data->{TITLE}{content} // ''; | |
my $link = $data->{URL_LINK}{content} // ''; | |
$link =~ s#^.+http#http#; | |
$link =~ s#'.+##; | |
my $geo = $p->{Point}{coordinates} // ''; | |
print qq("$title", "$name", "$link", "$geo"\n); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment