Browse Source

supply: take weight/volume as flags

raylu 3 weeks ago
parent
commit
11ea61d64f
2 changed files with 16 additions and 5 deletions
  1. 1 0
      pyproject.toml
  2. 15 5
      supply.py

+ 1 - 0
pyproject.toml

@@ -5,4 +5,5 @@ requires-python = '>=3.13'
 dependencies = [
 	'cbor2',
 	'httpx',
+	'typed-argument-parser',
 ]

+ 15 - 5
supply.py

@@ -4,15 +4,25 @@ import collections
 import dataclasses
 import json
 import math
-import sys
 import tomllib
 import typing
 
+import tap
+
 import cache
 
+class Args(tap.Tap):
+	planets: tuple[str, ...]
+	weight: float
+	volume: float
+
+	def configure(self) -> None:
+		self.add_argument('planets', nargs='+', metavar='planet') # take planets as positional args instead of flag
+
 def main() -> None:
-	planet_names = sys.argv[1:]
-	planets = [Planet(fio_burn) for fio_burn in get_fio_burn(planet_names)]
+	args = Args().parse_args()
+
+	planets = [Planet(fio_burn) for fio_burn in get_fio_burn(args.planets)]
 	raw_materials: typing.Sequence[Material] = cache.get('https://rest.fnar.net/material/allmaterials')
 	materials = {mat['Ticker']: mat for mat in raw_materials}
 
@@ -38,7 +48,7 @@ def main() -> None:
 			buy, weight_used, volume_used = planet.buy_for_target(materials, target_days)
 			total_weight_used += weight_used
 			total_volume_used += volume_used
-			if total_weight_used > 500 or total_volume_used > 500:
+			if total_weight_used > args.weight or total_volume_used > args.volume:
 				load_more = False
 				break
 			optimal[planet.name] = buy
@@ -69,7 +79,7 @@ def main() -> None:
 			{'type': 'MTRA', 'name': 'TransferAction', 'group': 'A1',
 				'origin': 'Hortus Station Warehouse', 'dest': 'Configure on Execution'},
 		],
-		'global': {'name': 'supply ' + ' '.join(planet_names)},
+		'global': {'name': 'supply ' + ' '.join(args.planets)},
 		'groups': [{
 			'type': 'Manual', 'name': 'A1', 'materials': {mat: amount for mat, amount in combined_buy.items()}
 		}],