summaryrefslogtreecommitdiff
path: root/nodejs/automation/exploration.js
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-01 23:13:13 +0200
committerJulien Dessaux2023-07-01 23:13:13 +0200
commit36cc33f9e96a38ecea98ac8d26275b4828347d80 (patch)
tree653dcea7e656ec815fc0a1fa5664a6b89abccaa3 /nodejs/automation/exploration.js
parentFixed prepared statements (diff)
downloadspacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.gz
spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.bz2
spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.zip
Moved the nodejs agent to its own subfolder to make room for my haskell agent
Diffstat (limited to 'nodejs/automation/exploration.js')
-rw-r--r--nodejs/automation/exploration.js21
1 files changed, 21 insertions, 0 deletions
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();
+}