Advertisement
Guest User

/warehouse/query

a guest
Dec 28th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict"
  2.  
  3. const request = require('superagent')
  4. const Promise = require("bluebird")
  5.  
  6. const accessToken = '*****'
  7.  
  8. let pageSize = 100
  9. let taxonID = 'MX.61523'
  10.  
  11. function search()
  12. {
  13.     request
  14.     .get('https://apitest.laji.fi/v0/warehouse/query/count' )
  15.     .query({  taxonId:taxonID,  
  16.               access_token: accessToken })
  17.     .then(function(res)
  18.     {
  19.         let total = res.body.total
  20.         let nbrPages = Math.floor(total/pageSize)+1
  21.  
  22.         let pageQueries = []
  23.  
  24.         for ( let i=0; i<nbrPages; i++ )
  25.         {
  26.             pageQueries.push( { "taxonID":taxonID, "page":i+1 } )
  27.         }
  28.  
  29.         Promise.map( pageQueries, getResultPage, { concurrency: 10 })
  30.         .then( function ( resultPages )
  31.         {
  32.             resultPages.forEach( page => {
  33.                 page.body.results.forEach( result =>
  34.                 {
  35.                     if ( result.gathering )
  36.                     {                      
  37.                         console.log( result.gathering.conversions.ykj )
  38.                     }
  39.                 })
  40.             })
  41.         })
  42.     })      
  43. }
  44.  
  45. function getResultPage( query )
  46. {
  47.     return request
  48.     .get('https://apitest.laji.fi/v0/warehouse/query/list' )
  49.     .query({  taxonId: query.taxonID,
  50.               pageSize: 100,  
  51.               page: query.page,  
  52.               selected: 'gathering.conversions.ykj',
  53.               access_token: accessToken })
  54. }
  55.  
  56. search()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement