Browse Source

calculate burn

raylu 1 month ago
commit
acca558f13
3 changed files with 64 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 7 0
      pyproject.toml
  3. 55 0
      supply.py

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+config.toml
+uv.lock

+ 7 - 0
pyproject.toml

@@ -0,0 +1,7 @@
+[project]
+name = 'pruncalc'
+version = '0'
+requires-python = '>=3.13'
+dependencies = [
+    'httpx',
+]

+ 55 - 0
supply.py

@@ -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()