Automated logging of TBs and GeoCoins at GeoCaching.com

16 11 2009

I have taken up a new hobby called Geocaching some months ago, where you run around with a GPS device in order to find hidden “caches” along the countryside. One thing that you can find in these caches are so-called “trackables” which own a tracking number. You enter this tracking number on the Geocaching.com website to claim that you have seen and maybe have taken the trackable item.

When attending an event together with other Geocachers, the number of trackable items present can become really big – there were over 80 of them for the last get-together that I went to. Since I don’t want to track all of these items by hand, I remembered about the possibility to automate web browsers with Selenium. After I got a list of the tracking numbers, I wrote a small script to handle the “Discover It!” requests to the GC.com website.

Here it is:

<?php

  $trackables = array('ABCDEF', 'GHIJKL', 'MNOPQR', 'STUVWX');

  // load API
  require_once 'Testing/Selenium.php';
  $selenium = new Testing_Selenium('*firefox /opt/firefox/firefox-bin', 'http://www.geocaching.com/login/');
  $result = $selenium->start();

  $selenium->open('http://www.geocaching.com/login/');
  $selenium->waitForPageToLoad('20000');

  // login
  $selenium->type('id=ctl00_ContentBody_myUsername', '___YOUR_ACCOUNT_NAME___');
  $selenium->type('id=ctl00_ContentBody_myPassword', '___YOUR_ACCOUNT_PASS___');
  $selenium->click('id=ctl00_ContentBody_Button1');
  $selenium->waitForPageToLoad('20000');

  // discover trackables
  foreach ($trackables as $track) {
    $selenium->open("http://www.geocaching.com/track/details.aspx?tracker=$track");
    $selenium->waitForPageToLoad('20000');

    $selenium->click('link=Found It? Log it!');
    $selenium->waitForPageToLoad('20000');
    $selenium->select('id=LogBookPanel1_ddLogType', 'label=Discovered It');
    $selenium->type('id=LogBookPanel1_tbCode', $track);
    $selenium->type('id=LogBookPanel1_tbLogInfo', '___DISCOVER_MESSAGE___');
    $selenium->click('id=LogBookPanel1_LogButton');
    $selenium->waitForPageToLoad('20000');
  }

  // close browser
  $selenium->close();
  $selenium->stop();

?>
Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: