Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created March 19, 2017 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnilchee/e770ebb199e5bea00a9fe0b1a2bd0b7a to your computer and use it in GitHub Desktop.
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
[openweathermap]
app_id = "__appid__"
zip_code = 98101
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