1 # Get driving direction using Google Directions API.
3 page = require('webpage').create()
4 system = require 'system'
6 if system.args.length < 3
7 console.log 'Usage: direction.coffee origin destination'
8 console.log 'Example: direction.coffee "San Diego" "Palo Alto"'
11 origin = system.args[1]
13 page.open encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin +
14 '&destination=' + dest + '&units=imperial&mode=driving&sensor=false'),
16 if status isnt 'success'
17 console.log 'Unable to access network'
19 steps = page.content.match(/<html_instructions>(.*)<\/html_instructions>/ig)
21 console.log 'No data available for ' + origin + ' to ' + dest
24 ins = ins.replace(/\</ig, '<').replace(/\>/ig, '>')
25 ins = ins.replace(/\<div/ig, '\n<div')
26 ins = ins.replace(/<.*?>/g, '')
29 console.log page.content.match(/<copyrights>.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '')