Created
March 3, 2015 14:42
-
-
Save runeh/2a03e2931c3618515a74 to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var highland = require("highland"); | |
var request = require("request-promise"); | |
var cowsay = require("cowsay"); | |
var promiseToStream = highland; | |
var arrayToStream = highland; | |
var pollerToStream = highland; | |
function cowPageGenerator(url) { | |
var page = 1; | |
return function (push, next) { | |
console.log("PLANG"); | |
push(null, request(url, { qs: { page: page++ } })); | |
next(); | |
}; | |
} | |
function cowStream(url) { | |
return pollerToStream(cowPageGenerator(url)).flatMap(promiseToStream).map(JSON.parse).map(function (e) { | |
return e.entries; | |
}).flatMap(arrayToStream); | |
} | |
var url = "http://hotell.difi.no/api/json/mattilsynet/husdyrregisteret/storfeindivider"; | |
function entryString(cow) { | |
return cow.individmerke + ": " + cow.kjonn; | |
} | |
cowStream(url).ratelimit(1, 1000).map(entryString).map(function (e) { | |
return cowsay.say({ text: e, e: "oO", T: "U " }); | |
}).each(console.log); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment