|
@@ -1,6 +1,8 @@
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
+import collections
|
|
|
import concurrent.futures
|
|
import concurrent.futures
|
|
|
|
|
+import sys
|
|
|
import typing
|
|
import typing
|
|
|
|
|
|
|
|
import tap
|
|
import tap
|
|
@@ -8,18 +10,39 @@ import tap
|
|
|
import cache
|
|
import cache
|
|
|
|
|
|
|
|
class Args(tap.Tap):
|
|
class Args(tap.Tap):
|
|
|
- planets: list[str]
|
|
|
|
|
|
|
+ planets: list[str] = []
|
|
|
sector: tuple[str, ...] = ()
|
|
sector: tuple[str, ...] = ()
|
|
|
|
|
|
|
|
def configure(self) -> None:
|
|
def configure(self) -> None:
|
|
|
- self.add_argument('planets', nargs='+', metavar='planet') # take planets as positional args instead of flag
|
|
|
|
|
|
|
+ self.add_argument('planets', nargs='*', metavar='planet') # take planets as positional args instead of flag
|
|
|
|
|
|
|
|
def main() -> None:
|
|
def main() -> None:
|
|
|
args = Args().parse_args()
|
|
args = Args().parse_args()
|
|
|
if args.sector:
|
|
if args.sector:
|
|
|
- all_planets: typing.Sequence[Planet] = cache.get('https://rest.fnar.net/planet/allplanets')
|
|
|
|
|
|
|
+ sectors = []
|
|
|
|
|
+ all_sector_ids, sector_systems = get_sectors()
|
|
|
|
|
+ for sector in args.sector:
|
|
|
|
|
+ if len(sector) == 2:
|
|
|
|
|
+ if len(sector_ids := all_sector_ids[sector]) > 1:
|
|
|
|
|
+ print(sector, 'has multiple sector ids')
|
|
|
|
|
+ for sector_id in sector_ids:
|
|
|
|
|
+ print(f'\t{sector_id}:', ', '.join(system['Name'] for system in sector_systems[sector_id]))
|
|
|
|
|
+ return
|
|
|
|
|
+ else:
|
|
|
|
|
+ (sector_id,) = sector_ids
|
|
|
|
|
+ sectors.append(sector_id)
|
|
|
|
|
+ elif sector.startswith('sector-'):
|
|
|
|
|
+ sectors.append(sector)
|
|
|
|
|
+ else:
|
|
|
|
|
+ sys.exit(f'invalid sector: {sector}')
|
|
|
|
|
+
|
|
|
|
|
+ system_ids = set()
|
|
|
|
|
+ for sector_id in sectors:
|
|
|
|
|
+ system_ids.update(system['SystemId'] for system in sector_systems[sector_id])
|
|
|
|
|
+
|
|
|
|
|
+ all_planets: typing.Sequence[Planet] = cache.get('https://rest.fnar.net/planet/allplanets/full')
|
|
|
for planet in all_planets:
|
|
for planet in all_planets:
|
|
|
- if planet['PlanetNaturalId'].startswith(args.sector):
|
|
|
|
|
|
|
+ if planet['SystemId'] in system_ids:
|
|
|
args.planets.append(planet['PlanetName'])
|
|
args.planets.append(planet['PlanetName'])
|
|
|
|
|
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
|
@@ -30,12 +53,29 @@ def main() -> None:
|
|
|
continue
|
|
continue
|
|
|
print(f'\t{base["OwnerCode"]}\t{base["OwnerName"]}')
|
|
print(f'\t{base["OwnerCode"]}\t{base["OwnerName"]}')
|
|
|
|
|
|
|
|
|
|
+def get_sectors() -> tuple[typing.Mapping[str, typing.Collection[str]], typing.Mapping[str, typing.Sequence[System]]]:
|
|
|
|
|
+ systems: typing.Sequence[System] = cache.get('https://rest.fnar.net/systemstars')
|
|
|
|
|
+ sector_ids = collections.defaultdict(set)
|
|
|
|
|
+ sector_systems = collections.defaultdict(list)
|
|
|
|
|
+ for system in systems:
|
|
|
|
|
+ sector_name = system['NaturalId'][:2]
|
|
|
|
|
+ sector_ids[sector_name].add(system['SectorId'])
|
|
|
|
|
+ sector_systems[system['SectorId']].append(system)
|
|
|
|
|
+ return sector_ids, sector_systems
|
|
|
|
|
+
|
|
|
def get_bases(planet: str) -> typing.Sequence[Site]:
|
|
def get_bases(planet: str) -> typing.Sequence[Site]:
|
|
|
return cache.get('https://rest.fnar.net/planet/sites/' + planet)
|
|
return cache.get('https://rest.fnar.net/planet/sites/' + planet)
|
|
|
|
|
|
|
|
|
|
+class System(typing.TypedDict):
|
|
|
|
|
+ SystemId: str
|
|
|
|
|
+ NaturalId: str
|
|
|
|
|
+ Name: str
|
|
|
|
|
+ SectorId: str
|
|
|
|
|
+
|
|
|
class Planet(typing.TypedDict):
|
|
class Planet(typing.TypedDict):
|
|
|
PlanetNaturalId: str
|
|
PlanetNaturalId: str
|
|
|
PlanetName: str
|
|
PlanetName: str
|
|
|
|
|
+ SystemId: str
|
|
|
|
|
|
|
|
class Site(typing.TypedDict):
|
|
class Site(typing.TypedDict):
|
|
|
OwnerName: int
|
|
OwnerName: int
|