|
|
@@ -0,0 +1,55 @@
|
|
|
+from __future__ import annotations
|
|
|
+
|
|
|
+import sys
|
|
|
+import tomllib
|
|
|
+import typing
|
|
|
+
|
|
|
+import httpx
|
|
|
+
|
|
|
+def main() -> None:
|
|
|
+ planet = sys.argv[1].casefold()
|
|
|
+ burn = planet_burn(planet)
|
|
|
+
|
|
|
+ inventory = {item['MaterialTicker']: item['MaterialAmount'] for item in burn['Inventory']}
|
|
|
+ producing = frozenset(item['MaterialTicker'] for item in burn['OrderProduction'])
|
|
|
+ for consumption in burn['OrderConsumption'] + burn['WorkforceConsumption']:
|
|
|
+ ticker = consumption['MaterialTicker']
|
|
|
+ if ticker in producing:
|
|
|
+ continue
|
|
|
+ avail = inventory.get(ticker, 0)
|
|
|
+ days = avail / consumption['DailyAmount']
|
|
|
+ print(f'{ticker}: {avail} ({consumption['DailyAmount']:.2f}/d) → {days:.2f} d')
|
|
|
+
|
|
|
+def planet_burn(planet: str) -> PlanetData:
|
|
|
+ with open('config.toml', 'rb') as f:
|
|
|
+ config = tomllib.load(f)
|
|
|
+ client = httpx.Client(headers={'Authorization': config['fio_api_key']})
|
|
|
+
|
|
|
+ r = client.get('https://rest.fnar.net/fioweb/burn/user/' + config['username'])
|
|
|
+ r.raise_for_status()
|
|
|
+ planets: list[PlanetData] = r.json()
|
|
|
+ for planet_data in planets:
|
|
|
+ name = planet_data['PlanetName']
|
|
|
+ if name.casefold() == planet:
|
|
|
+ assert planet_data['Error'] is None
|
|
|
+ return planet_data
|
|
|
+ raise ValueError(planet + ' not found')
|
|
|
+
|
|
|
+class PlanetData(typing.TypedDict):
|
|
|
+ PlanetName: str
|
|
|
+ Error: typing.Any
|
|
|
+ OrderConsumption: list[Amount]
|
|
|
+ WorkforceConsumption: list[Amount]
|
|
|
+ Inventory: list[Inventory]
|
|
|
+ OrderProduction: list[Amount]
|
|
|
+
|
|
|
+class Amount(typing.TypedDict):
|
|
|
+ MaterialTicker: str
|
|
|
+ DailyAmount: float
|
|
|
+
|
|
|
+class Inventory(typing.TypedDict):
|
|
|
+ MaterialTicker: str
|
|
|
+ MaterialAmount: int
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|