Last active
August 29, 2015 14:20
-
-
Save 1ambda/16f5ae62a48f399d42ac to your computer and use it in GitHub Desktop.
Weather Information Using Rx Javascript
This file contains hidden or 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
"use strict"; | |
var Rx = require('rx'); | |
var axios = require('axios'); | |
var city = 'seoul'; | |
var api = 'http://api.openweathermap.org/data/2.5/weather?mode=json&units=metric&q=' + city; | |
var p = axios.get(api); /* promise */ | |
var o = Rx.Observable | |
.interval(1000 /* ms */) | |
.selectMany(function() { | |
return Rx.Observable.fromPromise(p); | |
}); | |
o.subscribe(function(res) { | |
var weather = res.data.weather; | |
var temp = res.data.main.temp; | |
console.log("temp: " + temp); | |
console.log("weather: " + weather[0].description); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
response