0ptr/nullptr/atlas_builder.py
2023-06-12 11:03:54 +02:00

63 lines
1.5 KiB
Python

from time import sleep
from nullptr.util import *
from threading import Thread
class AtlasBuilder:
def __init__(self, store, api):
self.store = store
self.api = api
self.stop_auto = False
def wait_for_stop(self):
input()
self.stop_auto = True
print('stopping...')
def run(self, page=1):
print('universe mode. hit enter to stop')
t = Thread(target=self.wait_for_stop)
t.daemon = True
t.start()
self.all_systems(int(page))
print('manual mode')
def all_specials(self, waypoints):
for w in waypoints:
if self.stop_auto:
break
if 'MARKETPLACE' in w.traits:
self.api.marketplace(w)
print(f'marketplace at {w}')
sleep(0.5)
if w.type == 'JUMP_GATE':
self.api.jumps(w)
print(f'jumpgate at {w}')
def all_waypoints(self, systems):
for s in systems:
if self.stop_auto:
break
r = self.api.list_waypoints(s)
self.all_specials(r)
self.store.flush()
sleep(0.5)
def all_systems(self, start_page):
self.stop_auto = False
data = self.api.list_systems(start_page)
pages = total_pages(self.api.last_meta)
print(f'{pages} pages of systems')
print(f'page {1}: {len(data)} results')
self.all_waypoints(data)
self.store.flush()
for p in range(start_page+1, pages):
if self.stop_auto:
break
data = self.api.list_systems(p)
print(f'page {p}: {len(data)} systems')
self.all_waypoints(data)
sleep(0.5)
self.store.flush()