Skip to content

Instantly share code, notes, and snippets.

@1ambda
Last active August 29, 2015 14:20
Show Gist options
  • Save 1ambda/16f5ae62a48f399d42ac to your computer and use it in GitHub Desktop.
Save 1ambda/16f5ae62a48f399d42ac to your computer and use it in GitHub Desktop.
Weather Information Using Rx Javascript
"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);
});
@1ambda
Copy link
Author

1ambda commented May 10, 2015

response

temp: 15
weather: Sky is Clear
temp: 15
weather: Sky is Clear
temp: 15
weather: Sky is Clear
temp: 15
weather: Sky is Clear
temp: 15
weather: Sky is Clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment