mirror of
https://gitlab.com/tiggr/enex2kml.git
synced 2024-12-25 16:31:00 +01:00
added license and help text
This commit is contained in:
parent
53f0c40414
commit
782fa6f694
143
enex2kml.pl
143
enex2kml.pl
@ -1,4 +1,17 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
|
#
|
||||||
|
# This script converts the XML export file from Evernote to a
|
||||||
|
# kml file for use with Google Earth.
|
||||||
|
#
|
||||||
|
# (c) 2013 by Marcus J. Ertl (http://www.colorful-sky.de/)
|
||||||
|
#
|
||||||
|
# This script is free to use and modify under the Creative Commones
|
||||||
|
# Attribution-ShareAlike 3.0 Unported License. For more about this license
|
||||||
|
# please visit http://creativecommons.org/licenses/by-sa/3.0/deed.de
|
||||||
|
#
|
||||||
|
# This script is shared without any support or warranty.
|
||||||
|
# Just use it on your own risk.
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Encode;
|
use Encode;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
@ -10,53 +23,58 @@ my $outFile = '';
|
|||||||
my $verbose = 0;
|
my $verbose = 0;
|
||||||
my $showSkipped = 0;
|
my $showSkipped = 0;
|
||||||
my $foldername = 'Evernote';
|
my $foldername = 'Evernote';
|
||||||
|
my $help = 0;
|
||||||
|
|
||||||
GetOptions( 'i|input=s' => \$inFile,
|
GetOptions( 'i|input=s' => \$inFile,
|
||||||
'o|output=s' => \$outFile,
|
'o|output=s' => \$outFile,
|
||||||
'v|verbose' => \$verbose,
|
'v|verbose' => \$verbose,
|
||||||
's|showSkipped' => \$showSkipped,
|
's|showSkipped' => \$showSkipped,
|
||||||
'f|folder=s' => \$foldername);
|
'f|folder=s' => \$foldername,
|
||||||
|
'h|help' => \$help);
|
||||||
|
|
||||||
my $count = 0;
|
if ($help || $inFile eq '' || $outFile eq '') {
|
||||||
my $exported = 0;
|
printHelp();
|
||||||
|
} else {
|
||||||
|
my $count = 0;
|
||||||
|
my $exported = 0;
|
||||||
|
|
||||||
my $parser = XML::LibXML->new();
|
my $parser = XML::LibXML->new();
|
||||||
my $notes = $parser->parse_file($inFile);
|
my $notes = $parser->parse_file($inFile);
|
||||||
|
|
||||||
my $kml = XML::LibXML::Document->new('1.0', 'utf-8');
|
my $kml = XML::LibXML::Document->new('1.0', 'utf-8');
|
||||||
my $root = $kml->createElement('kml');
|
my $root = $kml->createElement('kml');
|
||||||
$root->setAttribute('xmlns'=> 'http://www.opengis.net/kml/2.2');
|
$root->setAttribute('xmlns'=> 'http://www.opengis.net/kml/2.2');
|
||||||
my $document = $kml->createElement('Document');
|
my $document = $kml->createElement('Document');
|
||||||
my $folder = $kml->createElement('Folder');
|
my $folder = $kml->createElement('Folder');
|
||||||
my $name = $kml->createElement('name');
|
my $name = $kml->createElement('name');
|
||||||
$name->appendTextNode($foldername);
|
$name->appendTextNode($foldername);
|
||||||
$root->appendChild($document);
|
$root->appendChild($document);
|
||||||
$folder->appendChild($name);
|
$folder->appendChild($name);
|
||||||
$kml->setDocumentElement($root);
|
$kml->setDocumentElement($root);
|
||||||
|
|
||||||
my $style = $kml->createElement('Style');
|
my $style = $kml->createElement('Style');
|
||||||
$style->setAttribute('id' => 'done_style');
|
$style->setAttribute('id' => 'done_style');
|
||||||
my $iconStyle = $kml->createElement('IconStyle');
|
my $iconStyle = $kml->createElement('IconStyle');
|
||||||
$style->appendChild($iconStyle);
|
$style->appendChild($iconStyle);
|
||||||
my $scale = $kml->createElement('scale');
|
my $scale = $kml->createElement('scale');
|
||||||
$scale->appendTextNode('1.3');
|
$scale->appendTextNode('1.3');
|
||||||
$iconStyle->appendChild($scale);
|
$iconStyle->appendChild($scale);
|
||||||
my $icon = $kml->createElement('Icon');
|
my $icon = $kml->createElement('Icon');
|
||||||
$iconStyle->appendChild($icon);
|
$iconStyle->appendChild($icon);
|
||||||
my $href = $kml->createElement('href');
|
my $href = $kml->createElement('href');
|
||||||
$href->appendTextNode('http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png');
|
$href->appendTextNode('http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png');
|
||||||
$icon->appendChild($href);
|
$icon->appendChild($href);
|
||||||
my $hotspot = $kml->createElement('hotSpot');
|
my $hotspot = $kml->createElement('hotSpot');
|
||||||
$hotspot->setAttribute('x', '20');
|
$hotspot->setAttribute('x', '20');
|
||||||
$hotspot->setAttribute('y', '2');
|
$hotspot->setAttribute('y', '2');
|
||||||
$hotspot->setAttribute('xunits', 'pixels');
|
$hotspot->setAttribute('xunits', 'pixels');
|
||||||
$hotspot->setAttribute('yunits', 'pixels');
|
$hotspot->setAttribute('yunits', 'pixels');
|
||||||
$icon->appendChild($hotspot);
|
$icon->appendChild($hotspot);
|
||||||
|
|
||||||
$document->appendChild($style);
|
$document->appendChild($style);
|
||||||
$document->appendChild($folder);
|
$document->appendChild($folder);
|
||||||
|
|
||||||
foreach my $note ($notes->findnodes('/en-export/note')) {
|
foreach my $note ($notes->findnodes('/en-export/note')) {
|
||||||
my($title) = $note->findnodes('./title');
|
my($title) = $note->findnodes('./title');
|
||||||
my($lat) = $note->findnodes('./note-attributes/latitude');
|
my($lat) = $note->findnodes('./note-attributes/latitude');
|
||||||
my($long) = $note->findnodes('./note-attributes/longitude');
|
my($long) = $note->findnodes('./note-attributes/longitude');
|
||||||
@ -100,16 +118,51 @@ foreach my $note ($notes->findnodes('/en-export/note')) {
|
|||||||
} elsif ($showSkipped) {
|
} elsif ($showSkipped) {
|
||||||
print encode_utf8("Skipped: ".$title->to_literal."\n");
|
print encode_utf8("Skipped: ".$title->to_literal."\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
open KMLOUT, ">", $outFile or die $!;
|
||||||
|
print KMLOUT $kml->toString(1);
|
||||||
|
close KMLOUT;
|
||||||
|
|
||||||
|
my $skipped = $count-$exported;
|
||||||
|
print "\ninput:\t$inFile\n";
|
||||||
|
print "output:\t$outFile\n";
|
||||||
|
print "Notes read:\t$count\n";
|
||||||
|
print "Notes exported:\t$exported\n";
|
||||||
|
print "Notes skipped:\t".$skipped."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub printHelp {
|
||||||
|
print <<"EOT";
|
||||||
|
|
||||||
open KMLOUT, ">", $outFile or die $!;
|
\033[1menex2kml.pl
|
||||||
print KMLOUT $kml->toString(1);
|
===========\033[0m
|
||||||
close KMLOUT;
|
|
||||||
|
|
||||||
my $skipped = $count-$exported;
|
This script converts the XML export file from Evernote to a
|
||||||
print "\ninput:\t$inFile\n";
|
kml file for use with Google Earth.
|
||||||
print "output:\t$outFile\n";
|
|
||||||
print "Notes read:\t$count\n";
|
(c) 2013 by Marcus J. Ertl (http://www.colorful-sky.de/)
|
||||||
print "Notes exported:\t$exported\n";
|
|
||||||
print "Notes skipped:\t".$skipped."\n";
|
This script is free to use and modify under the Creative Commones
|
||||||
|
Attribution-ShareAlike 3.0 Unported License. For more about this license
|
||||||
|
please visit http://creativecommons.org/licenses/by-sa/3.0/deed.de
|
||||||
|
|
||||||
|
\033[1mUsage\033[0m
|
||||||
|
enex2kml.pl -i inputfile.enex -o outputfile.kml ...
|
||||||
|
|
||||||
|
\033[1mParameters\033[0m
|
||||||
|
i|input file to read
|
||||||
|
o|output file to write/overwrite
|
||||||
|
v|verbose show more infos
|
||||||
|
s|showSkipped show skipped entries
|
||||||
|
f|folder foldername in kml/Google Earth
|
||||||
|
h|help show this help
|
||||||
|
|
||||||
|
Google Earth and Evernote are Trademarks of their respective owners.
|
||||||
|
|
||||||
|
This script is shared without any support or warranty.
|
||||||
|
Just use it on your own risk.
|
||||||
|
|
||||||
|
EOT
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user