--- geopics.pl +++ geopics.pl 2010/11/10 13:35:18 @@ -22,10 +22,11 @@ use Encode::Unicode; use File::Path; use GD; +use XML::Twig; my($version) = "0.96"; -my($options) = "geopics [options] [input-files] +my($options) = "geopics [options] [input-files] Goes through all input files, extracts waypoints and retrieves all spoiler pics from GC. By default, it stores the results in the local directory 'spoiler' @@ -66,7 +67,7 @@ my($create_contents_pic) = 0; my($picdir) = "spoiler"; my($waypointfile) = "waypoints.txt"; -my($nospoilerfile) = "no\ spoiler\ found.txt"; +my($nospoilerfile) = "no_spoiler_found.txt"; my(%oldwaypts,@newwaypts,%seen,%nospoiler); my($wait,$char); my(@picnames,@picurls,$subpicdir); @@ -77,7 +78,6 @@ my($bild); my(@htmllist); my($htmlpagetext); -my($line); my($image,$newimage,$white,$black,$lix,$maxlix,$w,$h); my($line,$gpxformat); @@ -286,6 +286,7 @@ sub clean { my($name) = @_; + $name =~ s/.jpg//gsi; $name = beautify_name($name); # utf8::decode($name); # we really do not want any umlauts and special chars in file and link names! @@ -393,7 +394,7 @@ my($wayp) = @_; # no spoiler available for this waypoint - open (NOSPOILERLIST, ">>no spoiler found.txt") or die "Cannot append to no spoiler list. Exit!"; + open (NOSPOILERLIST, ">> $nospoilerfile") or die "Cannot append to no spoiler list. Exit!"; print NOSPOILERLIST "$wayp\n"; close(NOSPOILERLIST); } @@ -410,6 +411,30 @@ } } +sub GetCache +{ + my ($t, $cache) = @_; + my $wpt = $cache->parent('wpt'); + my $ID = $wpt->first_child_text('name'); + + if (!$seen{$ID}) { + push(@newwaypts,$ID); + $seen{$ID} = 1; + } +} + +sub GetWaypoint +{ + my ($t, $wpt) = @_; + my $ID = $wpt->{'att'}->{'id'}; + + if (!$seen{$ID}) { + push(@newwaypts,$ID); + $seen{$ID} = 1; + } +} + + if (!defined($ARGV[0])) { die("No input file specified!\n\n$options"); } @@ -465,33 +490,21 @@ } print "This is Geopics Version $version\n"; -check_download_servers(); -alert_if_new_version(1); +#check_download_servers(); +#alert_if_new_version(1); -$gpxformat = 0; -while (<>) { - chomp; - $gpxformat = 1 if (/([A-Z0-9]*?)<\/name>/) { - if (!$seen{$1}) { - push(@newwaypts,$1); - $seen{$1} = 1; - } - } - } else { - $line = $_; - while ($line =~ /([^0-9A-Z]|^)(GC[0-9A-Z]{2,5})($|[^0-9A-Z])/g) { - if (!$seen{$2}) { - push(@newwaypts,$2); - $seen{$2} = 1; - } - } - } +my $Parser = + new XML::Twig(twig_handlers=>{'gpx/wpt/groundspeak:cache' => \&GetCache, + 'loc/waypoint/name' => \&GetWaypoint}, + keep_encoding => 1); + +foreach my $InputFileName (@ARGV) { + $Parser->parsefile($InputFileName); + $Parser->purge; } if (! -d $picdir) { - print "\aDirectory '$picdir' does not exist. Shall I create it? (Y/N): "; + print "\aDirectory '$picdir' does not exist. Shall I create it? (Y/n): "; if($batch) { print "Y\n"; $char = 'Y'; @@ -510,7 +523,7 @@ die "Cannot change into diretory '$picdir'\n" unless chdir($picdir); if (-e "config.txt") { - print "\aDo you want to update '$picdir' with the same options as creating it? (Y/N): "; + print "\aDo you want to update '$picdir' with the same options as creating it? (Y/n): "; if($batch) { print "Y\n"; $char = 'Y'; @@ -741,5 +754,5 @@ close(INDEX); } -alert_if_new_version(0); +#alert_if_new_version(0); exit 0;