Public
Edited
Apr 22, 2024
Insert cell
Insert cell
function getEntries(options, wrapper = {items:[]} ) {
let { url, assign, maxPages, page, from, till, handle, pause, backoff = 0, ...rest } = options;

let base = new URL(url);
page = page ?? 1;
//from = from ?? parseInt(new Date('2010').getTime()/1000);
from = from ?? parseInt(new Date(Date.now()).getTime()/1000);
// base.searchParams.set('page', page );
base.searchParams.set('todate', from );
url = base.toString();

return Promises.delay(pause + (backoff * 1010)).then (()=>
new Promise(keep => fetch(url).then(d=>d.json()).then(d=>keep(d.data))))
.then(api => {
wrapper = {
site : options?.site,
quota : api.quota_remaining,
items : [ ...wrapper.items,...api.items ] };

console.log(api.quota_remaining,page);
from = new Date((api.items.at(-1)?.creation_date || from)*1000);
from.setDate(from.getDate()-15);
from = from.getTime()/1000;
if ( assign ) { assign(wrapper) } // for 'internal' use
if ( handle ) { handle(wrapper) } // for 'external' use
return /*api.has_more && /*api.*/ page < maxPages // v (un)comment wrapper to accumulate internally
? getEntries({...options , from, page: page + 1, backoff: api.backoff ?? 0 } , wrapper )
: wrapper;
})
}
Insert cell
config = ({
url:"https://sup.reflow.workers.dev/2.3/search/advanced?pagesize=99&order=desc&sort=creation&answers=1&title=nlp&site=stackoverflow&filter=!7-_2yiQTD8J7BDRj(IkPfl(sJdziwau)LO8a7(q0txVFT_8JBtAba6unW)A42)zEIJm9loKHsra",
maxPages:10,
pause:100
})
Insert cell
config.url
Insert cell
// temp = getEntries(config)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more