Update atlas_builder.py and commander.py

This commit is contained in:
Richard Bronkhorst 2023-06-12 11:03:54 +02:00
parent 80badca912
commit 20fb0b86f3
2 changed files with 65 additions and 51 deletions

62
nullptr/atlas_builder.py Normal file
View File

@ -0,0 +1,62 @@
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()

View File

@ -8,6 +8,7 @@ from nullptr.api import Api
from .util import *
from time import sleep
from threading import Thread
from nullptr.atlas_builder import AtlasBuilder
class Commander(CommandLine):
def __init__(self, store_dir='data', agent=None):
@ -15,6 +16,7 @@ class Commander(CommandLine):
self.store = Store(store_dir)
self.agent = self.select_agent(agent)
self.api = Api(self.store, self.agent)
self.atlas_builder = AtlasBuilder(self.store, self.api)
self.store.flush()
self.stop_auto= False
super().__init__()
@ -39,58 +41,8 @@ class Commander(CommandLine):
def do_register(self, faction):
self.api.register(faction.upper())
def wait_for_stop(self):
input()
self.stop_auto = True
print('stopping...')
def do_universe(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()
self.atlas_builder.run(page)
def do_systems(self, page=1):
r = self.api.list_systems(int(page))