3 Commits 5e4b361fea ... 39dd12e8bc

Author SHA1 Message Date
  raylu 39dd12e8bc planet_bases: handle FIO HTTP 204 2 weeks ago
  raylu 167c2e7351 production: add DW and GRA recipes 2 weeks ago
  raylu 7a82df2f1c link to corps 2 weeks ago
4 changed files with 13 additions and 1 deletions
  1. 6 0
      cache.py
  2. 4 1
      planet_bases.py
  3. 2 0
      ts/production.ts
  4. 1 0
      www/index.html

+ 6 - 0
cache.py

@@ -44,6 +44,9 @@ def get(url: str, *, json=True, headers=None, expiry=datetime.timedelta(minutes=
 		pass # fall through
 
 	r = get_with_retries(url, headers)
+	if r.status_code == 204:
+		raise NoContent
+
 	cache_path.parent.mkdir(parents=True, exist_ok=True)
 	with lzma.open(cache_path, 'wb') as f:
 		if json:
@@ -64,3 +67,6 @@ def get_with_retries(url: str, headers: httpx._types.HeaderTypes|None=None) -> h
 			else:
 				print(url, 'attempt', attempt+1, 'timed out; retrying...')
 	raise AssertionError
+
+class NoContent(Exception):
+	pass

+ 4 - 1
planet_bases.py

@@ -69,7 +69,10 @@ def get_bases(planet: str) -> typing.Sequence[Site]:
 	return cache.get('https://rest.fnar.net/planet/sites/' + planet, expiry=cache.ONE_DAY)
 
 def get_company(code: str) -> typing.Mapping[str, typing.Any]:
-	return cache.get('https://rest.fnar.net/company/code/' + code, expiry=cache.ONE_DAY)
+	try:
+		return cache.get('https://rest.fnar.net/company/code/' + code, expiry=cache.ONE_DAY)
+	except cache.NoContent:
+		return {'CorporationCode': None, 'CompanyCode': code, 'CompanyName': None, 'UserName': None}
 
 class System(typing.TypedDict):
 	SystemId: str

+ 2 - 0
ts/production.ts

@@ -112,8 +112,10 @@ async function recipeForMats(): Promise<{recipes: Record<string, Recipe>, extrac
 		'AL': '6xALO 1xO 1xC 1xFLX=>4xAL',
 		'C': '4xHCP=>4xC',
 		'DRF': '50xNFI 1xDCS=>1xDRF',
+		'DW': '10xH2O 1xPG=>10xDW',
 		'FE': '6xFEO 1xC 1xO 1xFLX=>4xFE',
 		'GL': '2xSIO 1xNA 1xSEN=>10xGL',
+		'GRA': '30xH2O 1xDDT 3xSOI=>6xGRA',
 		'HCP': '14xH2O 1xNS=>8xHCP',
 		'RE': '8xREO 1xC 1xO 1xFLX=>5xRE',
 		'RG': '10xGL 15xPG 1xSEN=>10xRG',

+ 1 - 0
www/index.html

@@ -13,6 +13,7 @@
 		<p><a href="roi.html">RoI</a></p>
 		<p><a href="buy.html">buy</a></p>
 		<p><a href="mat.html">material</a></p>
+		<p><a href="corps.html">corporations</a></p>
 		<p><a href="gov.html">government</a></p>
 	</main>
 </body>