Search this site


Metadata

Articles

Projects

Presentations

Google Maps Traffic to my phone.

Combining xulrunner, the Google Maps API, procmail, and imagemagick, I now have a way to request traffic data from google maps, all from my phone using only email (sms/mms).

The project itself isn't very polished, so I won't publish its location. However, I forwarded one traffic message from my phone to flickr. View it here. The picture is rotated because my phone's screen is taller than it is wide.

The entire process takes about 20 seconds (grab the map, screencapture, and email back to the phone).

Code for this lives here: https://semicomplete.googlecode.com/svn/traffic

jquerycmd+xpathtool == direction scraping on google

Show the first 3 steps that google maps tells you to take.
./getpath.sh "atlanta to nyc" | head -3
Head southeast on Trinity Ave SW toward Washington St SW        0.2mi
Slight left at Memorial Dr SW   0.3mi
Turn left at Martin St SE       361ft
Pipe that to lpr and you've got printed directions on under 5 seconds.

Why not just do this with plain page scraping? Because there's lots of javascript in google maps that presents the user with the directions. Firefox (Gecko, really) already parses it, so why bother reinventing the wheel? Let's use the wheel that already works.

Download jquery-20070623.1828.tar.gz. The download of jquerycmd comes with the xul app, 'jquerycmd.sh' and 'getpath.sh'.

For the lazy who just want to see the scripts:

At SuperHappyDevHouse 18

I've been working on the jquery commandline tool. The base features work, now all that remains is endlessly interating over adding features.
% ./jquerycmd.sh --url http://www.google.com --query img
<IMG width='276' height='110' src='/intl/en_ALL/images/logo.gif' alt='Google' />
% ./jquerycmd.sh --url http://www.technorati.com/ --query form
<FORM method='post' action='/query.php'>
        <div class="controls">
            <a href="/search?advanced">advanced search</a>
        </div>
... < remainder cut > ...

xulrunner command line adventures

Oh my god. If you followed the link, you surely noticd the 170ish lines in the example that shows you how to make use of command-line arguments from JavaScript. I totally forgot how nasty it is to often to simple things in XUL/XPCOM-land.

In my adventures of searching for telling teaching a small xulrunner application I'm working on to use the commandline, I found Crowbar, a project out of MIT that's pretty neat.

Basically I wanted the power of my xpathtool but twist it with some help from jQuery. A command-line jquery tool would let you do some pretty neat things with web scraping. Crowbar can already do the page fetching, but I want to do more. And no, by 'command-line jquery tool' I certainly do not mean this command line jquery documentation tool.

My frustration with XPCOM's burden-the-programmer design has me at the end of my patience for tonight. Basically I suck at XPCOM in JavaScript. I'll keep at it though, maybe something useful will come out. come out of it.

Update: Neat! While surfing through Crowbar's code for how they handle commandline arguments, I found this beauty:

/*
 * Process a series of command line arguments and modify default settings
 */
function processCommandLineArgs() {
  var nsCommandLine = window.arguments[0];
  nsCommandLine = nsCommandLine.QueryInterface(Components.interfaces.nsICommandLine);
  port = getCommandLineArg(nsCommandLine, 'port', port);
}
So, I try this out myself:
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        onload="alert(window.arguments[0].QueryInterface(Components.interfaces.nsICommandLine).getArgument(0))" />
And run xulrunner:
% xulrunner application.ini happypants
The result is this: