Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict"
- const request = require('superagent')
- const Promise = require("bluebird")
- const accessToken = '*****'
- let pageSize = 100
- let taxonID = 'MX.61523'
- function search()
- {
- request
- .get('https://apitest.laji.fi/v0/warehouse/query/count' )
- .query({ taxonId:taxonID,
- access_token: accessToken })
- .then(function(res)
- {
- let total = res.body.total
- let nbrPages = Math.floor(total/pageSize)+1
- let pageQueries = []
- for ( let i=0; i<nbrPages; i++ )
- {
- pageQueries.push( { "taxonID":taxonID, "page":i+1 } )
- }
- Promise.map( pageQueries, getResultPage, { concurrency: 10 })
- .then( function ( resultPages )
- {
- resultPages.forEach( page => {
- page.body.results.forEach( result =>
- {
- if ( result.gathering )
- {
- console.log( result.gathering.conversions.ykj )
- }
- })
- })
- })
- })
- }
- function getResultPage( query )
- {
- return request
- .get('https://apitest.laji.fi/v0/warehouse/query/list' )
- .query({ taxonId: query.taxonID,
- pageSize: 100,
- page: query.page,
- selected: 'gathering.conversions.ykj',
- access_token: accessToken })
- }
- search()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement