source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-macosx/examples/weather.coffee@ 31525

Last change on this file since 31525 was 31525, checked in by ak19, 7 years ago

Nathan provided more stuff: Themes folder contains Sencha's Themebuilder which generates GXT Themes. It includes the .theme and generated .jar files for the project theme.

File size: 1020 bytes
Line 
1page = require('webpage').create()
2system = require 'system'
3
4city = 'Mountain View, California'; # default
5if system.args.length > 1
6 city = Array.prototype.slice.call(system.args, 1).join(' ')
7url = encodeURI 'http://api.openweathermap.org/data/2.1/find/name?q=' + city
8
9console.log 'Checking weather condition for', city, '...'
10
11page.open url, (status) ->
12 if status isnt 'success'
13 console.log 'Error: Unable to access network!'
14 else
15 result = page.evaluate ->
16 return document.body.innerText
17 try
18 data = JSON.parse result
19 data = data.list[0]
20 console.log ''
21 console.log 'City:', data.name
22 console.log 'Condition:', data.weather.map (entry) ->
23 return entry.main
24 console.log 'Temperature:', Math.round(data.main.temp - 273.15), 'C'
25 console.log 'Humidity:', Math.round(data.main.humidity), '%'
26 catch e
27 console.log 'Error:', e.toString()
28
29 phantom.exit()
Note: See TracBrowser for help on using the repository browser.