This repository has been archived by the owner on May 30, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Coffeescript version of direction.js.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Get driving direction using Google Directions API. | ||
|
||
if phantom.state.length is 0 | ||
if phantom.args.length < 2 | ||
console.log 'Usage: direction.js origin destination' | ||
console.log 'Example: direction.js "San Diego" "Palo Alto"' | ||
phantom.exit(1) | ||
origin = phantom.args[0] | ||
dest = phantom.args[1] | ||
phantom.state = origin + ' to ' + dest | ||
phantom.open(encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin + | ||
'&destination=' + dest + '&units=imperial&mode=driving&sensor=false')) | ||
else | ||
if phantom.loadStatus is 'fail' | ||
console.log 'Unable to access network' | ||
else | ||
steps = phantom.content.match(/<html_instructions>(.*)<\/html_instructions>/ig); | ||
if not steps | ||
console.log 'No data available for ' + phantom.state | ||
else | ||
for ins in steps | ||
ins = ins.replace(/\</ig, '<').replace(/\>/ig, '>'); | ||
ins = ins.replace(/\<div/ig, '\n<div'); | ||
ins = ins.replace(/<.*?>/g, ''); | ||
console.log(ins); | ||
console.log '' | ||
console.log phantom.content.match(/<copyrights>.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '') | ||
phantom.exit() |