From 36cc33f9e96a38ecea98ac8d26275b4828347d80 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 1 Jul 2023 23:13:13 +0200 Subject: Moved the nodejs agent to its own subfolder to make room for my haskell agent --- nodejs/automation/exploration.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 nodejs/automation/exploration.js (limited to 'nodejs/automation/exploration.js') diff --git a/nodejs/automation/exploration.js b/nodejs/automation/exploration.js new file mode 100644 index 0000000..b35efe0 --- /dev/null +++ b/nodejs/automation/exploration.js @@ -0,0 +1,21 @@ +import * as db from '../database/systems.js'; +import * as api from '../lib/api.js'; + +// Retrieves all systems information, should be called only once after registering +export async function init() { + if (db.isInit()) { + return; + } + for (let page=1; true; ++page) { + const response = await api.send({endpoint: `/systems?limit=20&page=${page}`, priority:100}); + if (response.error !== undefined) { + throw response; + } + response.data.forEach(system => db.setSystem(system)); + if (response.meta.total <= response.meta.limit * page) { + break; + } + } + console.log('Finished retrieving all systems information'); + db.init(); +} -- cgit v1.2.3