From 05225ccdd7148e50cc40f07df479608209b5e8c5 Mon Sep 17 00:00:00 2001 From: Evan Battaglia Date: Sat, 17 Sep 2005 04:01:33 +0000 Subject: [PATCH] Tools that may or may not be helpful/fun --- tools/README | 5 ++ tools/gcget | 122 +++++++++++++++++++++++++++++++++++++++++ tools/googledirections | 4 ++ 3 files changed, 131 insertions(+) create mode 100644 tools/README create mode 100755 tools/gcget create mode 100755 tools/googledirections diff --git a/tools/README b/tools/README new file mode 100644 index 00000000..4447231d --- /dev/null +++ b/tools/README @@ -0,0 +1,5 @@ +Try this: +./googledirections "boston, ma" "new york, ny" | ../src/viking - + +Or edit gcget with your geocaching.com username and password and try this: +./gcget 94704 50 2>/dev/null | ../src/viking - diff --git a/tools/gcget b/tools/gcget new file mode 100755 index 00000000..f00b9473 --- /dev/null +++ b/tools/gcget @@ -0,0 +1,122 @@ +#!/usr/bin/perl +# +# gcget 34.25,-118.25 100 > yeah.loc +# ./gcget "Johnstown,CA" 10|gc2gpspoint - -|viking - +# +# have to make viking-remote allow multiple points. maybe just regular input + maps ? + +$USERNAME="username"; +$PASSWORD="password"; + +$what = $ARGV[0]; +if (!$what) { + print "Nothing to do!\nUsage: gcget zip/lat,lon/lat.mm.mmm,lon.mm.mmm/address [max]"; + exit(0); +} + + +$zip = $lat = $lon = ""; +if ( $what =~ /^(-?[0-9]{0,3}(\.[0-9]{0,9})?),(-?[0-9]{0,3}(\.[0-9]{0,9})?)$/ ) { + ($lat,$lon) = ($1,$3); +} 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})$/ ) { + $lat = $1 + ($1 < 0 ? -1 : 1) * $2 / 60; + $lon = $3 + ($3 < 0 ? -1 : 1) * $4 / 60; +} elsif ( $what =~ /^[0-9]{5}$/ ) { + $zip = $what; +} else { + $address = `gpsaddress.pl "$what"`; + if (not (($address) and $address =~ /^(-?[0-9]{1,3}(\.[0-9]{1,9})?) (-?[0-9]{1,3}(\.[0-9]{1,9})?)$/ )) { + die "gpsaddress failed looking up address '$what'\n" + } else { + ($lat,$lon) = ($1,$3); + } +} + +# turn on perl's safety features +use warnings; +use WWW::Mechanize; +use HTML::TableContentParser; +$browser = WWW::Mechanize->new(); + +$browser->get("http://www.geocaching.com/seek/"); +$browser->follow("log in"); +print STDERR $browser->title() . "\n"; +$browser->form_number(1); +$browser->field("myUsername", $USERNAME); +$browser->field("myPassword", $PASSWORD); +$browser->click(); +print STDERR $browser->title() . "\n\n"; + +if ( $zip ) { + $browser->form(1); + $browser->field("zip", $zip); +} else { + $browser->form(5); + $browser->field("origin_lat", $lat); + $browser->field("origin_long", $lon); +} +$browser->click(); + +$gcsdone = 0; +$maxgcs = $ARGV[1] ? $ARGV[1] : 1000000; + +print STDERR "\nPages: "; + +print "\n\n"; + + +while ( $gcsdone < $maxgcs ) { + +$p = HTML::TableContentParser->new(); +$tables = $p->parse($browser->content()); + +$t = ${$tables}[10]; +@rows = @{$t->{rows}}; +$r = $rows[8]; + +@cs = @{$r->{cells}}; + +$browser->form_number(1); + +for ( $i = 0; $i < 20; $i++ ) { + $r = $rows[4+(2*$i)]; + @cs = @{$r->{cells}}; + if ( $gcsdone < $maxgcs && (! $cs[1]->{data}) ) { + if ( $cs[7]->{data} =~ /name='CID' value='(.*)'>/ ) { + $browser->tick("CID", $1); + $gcsdone++; + } + } +} + +$browser->click("Download"); +@lines = split "\n", $browser->content(); +shift @lines; shift @lines; pop @lines; +print join "\n", @lines; +print "\n"; + +$browser->back(); +$form = $browser->form_name("Form1"); +$nextlink = $browser->find_link( text => "Next" ); +if ( $nextlink ) { + if ( ($nextlink->url()) =~ /_ctl([0-9]+)/ ) { + $form->push_input("hidden", {"name" => "ResultsPager:_ctl$1", value => ""}); + } else { + print STDERR "\n\nERROR\n\n"; + print "\n"; + exit(0); + } +} else { + print STDERR "\n\nDONE\n\n"; + print "\n"; + exit(0); +} +$browser->submit(); + +print STDERR "i"; + +} + +print STDERR "\n\nREACHED MAX\n\n"; +print "\n"; + diff --git a/tools/googledirections b/tools/googledirections new file mode 100755 index 00000000..061ecff5 --- /dev/null +++ b/tools/googledirections @@ -0,0 +1,4 @@ +#!/bin/bash +FROM="$1" +TO="$2" +(wget -O - "http://maps.google.com/maps?q=$FROM to $TO&output=xml" 2>/dev/null) | head -2 | tail -1 | sed 's/.*\(.*\)<\/page>.*/\1<\/page>/' | gpsbabel -i google -f - -o gpx -F - -- 2.39.5