Sha256: bc75ffb6f96309be08d4c0e43b8df5f0abb4fd3994f2a4f6ba18cd3b2972d983

Contents?: true

Size: 1.17 KB

Versions: 17

Compression:

Stored size: 1.17 KB

Contents

var page = require('webpage').create(),
    system = require('system'),
    city,
    url;

city = 'Mountain View, California'; // default
if (system.args.length > 1) {
    city = Array.prototype.slice.call(system.args, 1).join(' ');
}
url = encodeURI('http://api.openweathermap.org/data/2.1/find/name?q=' + city);

console.log('Checking weather condition for', city, '...');

page.open(url, function(status) {
    var result, data;
    if (status !== 'success') {
        console.log('Error: Unable to access network!');
    } else {
        result = page.evaluate(function () {
            return document.body.innerText;
        });
        try {
            data = JSON.parse(result);
            data = data.list[0];
            console.log('');
            console.log('City:', data.name);
            console.log('Condition:', data.weather.map(function(entry) {
                return entry.main;
            }).join(', '));
            console.log('Temperature:', Math.round(data.main.temp - 273.15), 'C');
            console.log('Humidity:', Math.round(data.main.humidity), '%');
        } catch (e) {
            console.log('Error:', e.toString());
        }
    }
    phantom.exit();
});

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.4.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.4.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.3.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.2.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.2.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.1.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.0.8 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.0.7 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
hooch-0.0.6 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.js
entangled-0.0.16 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.js
entangled-0.0.15 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.js
entangled-0.0.14 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.js
entangled-0.0.13 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.js
entangled-0.0.12 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.js
entangled-0.0.11 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.js
entangled-0.0.10 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.js