Commit 60b6ad28 authored by Philipp's avatar Philipp

initial import

parents
# GPX2ICS
Create .ics calendar files from geocaching.com .gpx PocketQueries
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use XML::Simple;
use utf8;
use Data::Dumper;
use Digest::MD5 qw(md5 md5_hex md5_base64);
local $| = 1;
my $VERSION = '0.1';
my $infile;
my $outfile;
my $outname;
my $xs;
my $wpt;
my $calendar;
my $year;
my $month;
my $day;
print "GPX2ICS v$VERSION by stimpy23 <stimpy\@gcwetterau.de>\n\n";
if ( ( !$ARGV[0] ) || ( ! -e $ARGV[0] ) ) {
print "Usage: $0 <inputfile.gpx> [<outputfile.ics>]\n";
} else {
print " - Reading $ARGV[0]... ";
$calendar = 'BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
PRODID:-//Apple Computer\, Inc//iCal 1.0//EN
X-WR-TIMEZONE;VALUE=TEXT:Europe/Berlin
X-WR-RELCALID;VALUE=TEXT:AD1EEE08-1337-DEAD-BEEF-0008492D1012
X-WR-CALNAME;VALUE=TEXT:Geocaching Events
METHOD:PUBLISH
';
$xs = XML::Simple->new();
eval { $infile = $xs->XMLin( $ARGV[0], ForceArray => 1, KeyAttr => {}, ); };
if ( $@ ) {
print "error!\n";
exit 0;
}
print "done.\n";
foreach $wpt ( @{$infile->{wpt}} ) {
utf8::encode($wpt->{type}[0]);
if ( $wpt->{type}[0] =~ m/Event Cache/ ) {
utf8::encode($wpt->{urlname}[0]);
utf8::encode($wpt->{time}[0]);
utf8::encode($wpt->{name}[0]);
utf8::encode($wpt->{desc}[0]);
$wpt->{time}[0] =~ m/^(\d{4})-(\d{2})-(\d{2}).*/; $year = $1; $month = $2; $day = $3;
$calendar .= 'BEGIN:VEVENT
CLASS:PUBLIC
SEQUENCE:0
SUMMARY:'.$wpt->{urlname}[0].'
DTSTAMP;TZID=Europe/Berlin:'.$year.$month.$day.'T000000
DTSTART;VALUE=DATE:'.$year.$month.$day.'
DESCRIPTION:'.$wpt->{desc}[0].'
ATTACH:http://chop.at/'.$wpt->{name}[0].'
PRIORITY:5
TRANSP:OPAQUE
UID:gcevents-'.$wpt->{name}[0].'-'.md5_hex($wpt->{name}[0]).'
END:VEVENT
';
}
}
$calendar .= 'END:VCALENDAR';
if ( $ARGV[1] ) {
$outname = $ARGV[1];
} else {
$outname = "$ARGV[0].ics";
}
print " - Writing $outname... ";
if ( not open( $outfile, q{>}, "$outname" ) ) {
print "error!\n";
exit 0;
}
print "done.\n";
print $outfile $calendar;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment