Upgrade to Pro — share decks privately, control downloads, hide ads and more …

お天気スマホアプリはもう要らない。かも。

Chachamaru
January 15, 2016
33

 お天気スマホアプリはもう要らない。かも。

東京Node学園付属小学校 1時限目 ~Node.js入門者向けLT大会&交流会~

Chachamaru

January 15, 2016
Tweet

Transcript

  1. Livedoor - Weather Hacks "forecasts" : [ { "dateLabel" :

    "ࠓ೔", "telop" : "੖ͷͪಶ", "date" : "2015-01-15", "temperature" : { "min" : null, "max" : { "celsius" : "11", "fahrenheit" : "51.8" } }, "image" : { "width" : 50, "url" : "http://weather.livedoor.com/img/icon/5.gif", "title" : "੖ͷͪಶ", "height" : 31 } }
  2. var http = require('http'); var url = 'http://weather.livedoor.com/forecast/webservice/json/v1? city=130010'; http.get(url,

    function(res) { var body = ''; res.setEncoding('utf8'); res.on('data', function(data) { body += data; }); res.on('end', function(data) { console.log(JSON.parse(body).forecasts[0].telop); }) });
  3. "forecasts" : [ { "dateLabel" : "ࠓ೔", "telop" : "੖ͷͪಶ",

    "date" : "2015-01-15", "temperature" : { "min" : null, "max" : { "celsius" : "11", "fahrenheit" : "51.8" } }, "image" : { "width" : 50, "url" : "http://weather.livedoor.com/img/icon/5.gif", "title" : "੖ͷͪಶ", "height" : 31 } }
  4. res.on('end', function(data) { var weather_data = JSON.parse(body); forecasts = weather_data['forecasts'];

    for (index in forecasts) { forecast = forecasts[index]; if (forecast.dateLabel === 'ࠓ೔') { weather = forecast['telop']; console.log(weather); } } })