Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / phantomjs / lib / phantom / examples / direction.coffee
1 # Get driving direction using Google Directions API.
2
3 page = require('webpage').create()
4 system = require 'system'
5
6 if system.args.length < 3
7   console.log 'Usage: direction.coffee origin destination'
8   console.log 'Example: direction.coffee "San Diego" "Palo Alto"'
9   phantom.exit 1
10 else
11   origin = system.args[1]
12   dest = system.args[2]
13   page.open encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin +
14                       '&destination=' + dest + '&units=imperial&mode=driving&sensor=false'),
15             (status) ->
16               if status isnt 'success'
17                 console.log 'Unable to access network'
18               else
19                 steps = page.content.match(/<html_instructions>(.*)<\/html_instructions>/ig)
20                 if not steps
21                   console.log 'No data available for ' + origin + ' to ' + dest
22                 else
23                   for ins in steps
24                     ins = ins.replace(/\&lt;/ig, '<').replace(/\&gt;/ig, '>')
25                     ins = ins.replace(/\<div/ig, '\n<div')
26                     ins = ins.replace(/<.*?>/g, '')
27                     console.log(ins)
28                   console.log ''
29                   console.log page.content.match(/<copyrights>.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '')
30               phantom.exit()