Skip to content

Instantly share code, notes, and snippets.

@nall
Created December 8, 2009 00:59
Show Gist options
  • Save nall/251327 to your computer and use it in GitHub Desktop.
Save nall/251327 to your computer and use it in GitHub Desktop.
Dump Garmin XML
#!/usr/bin/env perl
my $date = `date "+%m%d%y"`;
chomp($date);
my $tmpfile = "/tmp/GRMN_".$date.".xml.tmp";
my $file = "$ENV{HOME}/Documents/GRMN_logs/GRMN_".$date.".xml";
print "Reading from GPS...\n";
system("/Library/MotionBased/GpstoMb Xml=true GzipBase64=false > $tmpfile 2> /dev/null");
open(FILE, "<$tmpfile") or die("Cannot open $tmpfile for reading");
open(OUTFILE, ">$file") or die("Cannot open $file for writing");
my $print = 0;
while(<FILE>)
{
my $line = $_;
if($line =~ /^<\?xml version/)
{
$print = 1;
}
print OUTFILE $line if $print == 1;
if($line =~ /^<\/TrainingCenterDatabase>/)
{
$print = 0;
}
}
close(FILE);
close(OUTFILE);
unlink($tmpfile);
system("/usr/bin/gzip $file");
print "Results in: $file.gz\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment