source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-windows/examples/weather.js@ 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: 1.2 KB
Line 
1var page = require('webpage').create(),
2 system = require('system'),
3 city,
4 url;
5
6city = 'Mountain View, California'; // default
7if (system.args.length > 1) {
8 city = Array.prototype.slice.call(system.args, 1).join(' ');
9}
10url = encodeURI('http://api.openweathermap.org/data/2.1/find/name?q=' + city);
11
12console.log('Checking weather condition for', city, '...');
13
14page.open(url, function(status) {
15 var result, data;
16 if (status !== 'success') {
17 console.log('Error: Unable to access network!');
18 } else {
19 result = page.evaluate(function () {
20 return document.body.innerText;
21 });
22 try {
23 data = JSON.parse(result);
24 data = data.list[0];
25 console.log('');
26 console.log('City:', data.name);
27 console.log('Condition:', data.weather.map(function(entry) {
28 return entry.main;
29 }).join(', '));
30 console.log('Temperature:', Math.round(data.main.temp - 273.15), 'C');
31 console.log('Humidity:', Math.round(data.main.humidity), '%');
32 } catch (e) {
33 console.log('Error:', e.toString());
34 }
35 }
36 phantom.exit();
37});
Note: See TracBrowser for help on using the repository browser.