Răsfoiți Sursa

supply: handle items with no asks

raylu 1 lună în urmă
părinte
comite
056a0e98c6
1 a modificat fișierele cu 11 adăugiri și 5 ștergeri
  1. 11 5
      supply.py

+ 11 - 5
supply.py

@@ -58,9 +58,9 @@ def main() -> None:
 			weight_used += amount * materials[mat]['Weight']
 			volume_used += amount * materials[mat]['Volume']
 		if weight_used > args.weight:
-			print(f'\033[33mwarning:\033[0m need additional {weight_used - args.weight:.1f}t to pick up exports at {planet.name}')
+			print(yellow('warning'), f'need additional {weight_used - args.weight:.1f}t to pick up exports at {planet.name}')
 		if volume_used > args.volume:
-			print(f'\033[33mwarning:\033[0m need additional {volume_used - args.volume:.1f}㎥ to pick up exports at {planet.name}')
+			print(yellow('warning'), f'need additional {volume_used - args.volume:.1f}㎥ to pick up exports at {planet.name}')
 
 	print(cyan('\nload at CX:\n') + json.dumps({
 		'actions': [
@@ -170,9 +170,12 @@ def calculate_optimal(planets: typing.Sequence[Planet], materials: typing.Mappin
 						need -= min(need, avail)
 						warehouse[ticker] -= max(avail - need, 0)
 						sources.append(f'WH: {avail}')
-					cost = raw_prices[ticker]['Ask'] * need
-					print(f' (${cost:6.0f}) ' + ', '.join(sources))
-					total_cost += cost
+					if (ppu := raw_prices[ticker]['Ask']) is not None:
+						cost = ppu * need
+						print(f' (${cost:6.0f}) ' + ', '.join(sources))
+						total_cost += cost
+					else:
+						print(yellow(' no supply ') + ', '.join(sources))
 			else:
 				print()
 	print(f'\ntotal cost: {total_cost:,}')
@@ -198,6 +201,9 @@ def warehouse_inventory() -> dict[str, int]:
 			return {item['MaterialTicker']: item['MaterialAmount'] for item in storage['StorageItems']}
 	raise Exception("couldn't find HRT warehouse")
 
+def yellow(text: str) -> str:
+	return '\033[33m' + text + '\033[0m'
+
 def cyan(text: str) -> str:
 	return '\033[36m' + text + '\033[0m'