Created
March 3, 2015 14:25
-
-
Save runeh/9e7eafa7b6ec6c3591d8 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
const highland = require('highland'); | |
const request = require('request-promise') | |
const promiseToStream = highland; | |
const arrayToStream = highland; | |
const pollerToStream = highland; | |
function cowPageGenerator(url) { | |
let page = 1; | |
return (push, next) => { | |
push(null, request(url, {qs: {page: page++}})); | |
next(); | |
}; | |
} | |
function cowStream(url) { | |
return pollerToStream(cowPageGenerator(url)) | |
.flatMap(promiseToStream) | |
.map(JSON.parse) | |
.map(e => e.entries) | |
.flatMap(arrayToStream) | |
} | |
const url = "http://hotell.difi.no/api/json/mattilsynet/husdyrregisteret/storfeindivider"; | |
cowStream(url) | |
.ratelimit(1, 1000); | |
.each(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment