Sha256: ea8816f86b44c22362572f32bfcee2768c3fb47dea6f88004a3ac3368316a433

Contents?: true

Size: 1020 Bytes

Versions: 17

Compression:

Stored size: 1020 Bytes

Contents

page = require('webpage').create()
system = require 'system'

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, (status) ->
    if status isnt 'success'
        console.log 'Error: Unable to access network!'
    else
        result = page.evaluate ->
            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 (entry) ->
                return entry.main
            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.coffee
hooch-0.4.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.4.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.3.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.2.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.2.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.1.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.0.8 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.0.7 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
hooch-0.0.6 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/weather.coffee
entangled-0.0.16 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.coffee
entangled-0.0.15 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.coffee
entangled-0.0.14 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.coffee
entangled-0.0.13 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.coffee
entangled-0.0.12 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.coffee
entangled-0.0.11 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.coffee
entangled-0.0.10 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/weather.coffee