Created
March 19, 2017 08:29
-
-
Save gnilchee/e770ebb199e5bea00a9fe0b1a2bd0b7a to your computer and use it in GitHub Desktop.
Getting current conditions from openweathermanapi (pre-req: npm install --save coffee-script http config toml), place default.toml in config subdir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[openweathermap] | |
app_id = "__appid__" | |
zip_code = 98101 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http = require 'http' | |
config = require 'config' | |
zip_code = config.get('openweathermap.zip_code') | |
app_id = config.get('openweathermap.app_id') | |
url_path = "/data/2.5/weather?zip=#{zip_code},us&appid=#{app_id}&units=imperial" | |
http.get { host: 'api.openweathermap.org', path: url_path }, (res) -> | |
console.log 'statusCode:', res.statusCode | |
console.log 'content-type:', res.headers['content-type'] | |
data = '' | |
res.on 'data', (chunk) -> | |
data += chunk.toString() | |
res.on 'end', () -> | |
console.log 'Current Temperature:', JSON.parse(data)['main']['temp'] + '°F' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment