3 # gcget 34.25,-118.25 100 > yeah.loc
4 # ./gcget "Johnstown,CA" 10|gc2gpspoint - -|viking -
6 # have to make viking-remote allow multiple points. maybe just regular input + maps ?
13 print "Nothing to do!\nUsage: gcget zip/lat,lon/lat.mm.mmm,lon.mm.mmm/address [max]";
18 $zip = $lat = $lon = "";
19 if ( $what =~ /^(-?[0-9]{0,3}(\.[0-9]{0,9})?),(-?[0-9]{0,3}(\.[0-9]{0,9})?)$/ ) {
20 ($lat,$lon) = ($1,$3);
21 } elsif ( $what =~ /^(-?[0-9]{1,3})\.([0-9]{1,2}\.[0-9]{0,3}),(-?[0-9]{1,3})\.([0-9]{1,2}\.[0-9]{0,3})$/ ) {
22 $lat = $1 + ($1 < 0 ?
-1 : 1) * $2 / 60;
23 $lon = $3 + ($3 < 0 ?
-1 : 1) * $4 / 60;
24 } elsif ( $what =~ /^[0-9]{5}$/ ) {
27 $address = `gpsaddress.pl "$what"`;
28 if (not (($address) and $address =~ /^(-?[0-9]{1,3}(\.[0-9]{1,9})?) (-?[0-9]{1,3}(\.[0-9]{1,9})?)$/ )) {
29 die "gpsaddress failed looking up address '$what'\n"
31 ($lat,$lon) = ($1,$3);
35 # turn on perl's safety features
38 use HTML
::TableContentParser
;
39 $browser = WWW
::Mechanize
->new();
41 $browser->get("http://www.geocaching.com/seek/");
42 $browser->follow("log in");
43 print STDERR
$browser->title() . "\n";
44 $browser->form_number(1);
45 $browser->field("myUsername", $USERNAME);
46 $browser->field("myPassword", $PASSWORD);
48 print STDERR
$browser->title() . "\n\n";
52 $browser->field("zip", $zip);
55 $browser->field("origin_lat", $lat);
56 $browser->field("origin_long", $lon);
61 $maxgcs = $ARGV[1] ?
$ARGV[1] : 1000000;
63 print STDERR
"\nPages: ";
65 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<loc version=\"1.0\" src=\"Groundspeak\">\n";
68 while ( $gcsdone < $maxgcs ) {
70 $p = HTML
::TableContentParser
->new();
71 $tables = $p->parse($browser->content());
74 @rows = @
{$t->{rows
}};
79 $browser->form_number(1);
81 for ( $i = 0; $i < 20; $i++ ) {
84 if ( $gcsdone < $maxgcs && (! $cs[1]->{data
}) ) {
85 if ( $cs[7]->{data
} =~ /name='CID' value='(.*)'>/ ) {
86 $browser->tick("CID", $1);
92 $browser->click("Download");
93 @lines = split "\n", $browser->content();
94 shift @lines; shift @lines; pop @lines;
95 print join "\n", @lines;
96 print "</waypoint>\n";
99 $form = $browser->form_name("Form1");
100 $nextlink = $browser->find_link( text
=> "Next" );
102 if ( ($nextlink->url()) =~ /_ctl([0-9]+)/ ) {
103 $form->push_input("hidden", {"name" => "ResultsPager:_ctl$1", value
=> ""});
105 print STDERR
"\n\nERROR\n\n";
110 print STDERR
"\n\nDONE\n\n";
120 print STDERR
"\n\nREACHED MAX\n\n";