Эх сурвалжийг харах

popi_reimbursement: use most recent price

also show all prices used
raylu 1 сар өмнө
parent
commit
e3c58f9765
1 өөрчлөгдсөн 7 нэмэгдсэн , 1 устгасан
  1. 7 1
      popi_reimbursement.py

+ 7 - 1
popi_reimbursement.py

@@ -17,6 +17,7 @@ def main() -> None:
 	infras: typing.Sequence[Infrastructure] = cache.get(
 			'https://api.fnar.net/infrastructure?include_contributions=true&infrastructure=' + planet)
 	threshold = (datetime.datetime.now(datetime.UTC) - datetime.timedelta(days=60)).strftime('%Y-%m-%d')
+	used_prices: dict[str, float] = {}
 	for infra in infras:
 		print(infra['Type'])
 		infra['Contributions'].sort(key=lambda c: c['Time'])
@@ -27,6 +28,11 @@ def main() -> None:
 			for mat in contribution['Materials']:
 				price = prices.get(mat['Ticker'], 0)
 				print(f'\t\t{mat["Ticker"]} {mat["Amount"]} @ {price} = {mat["Amount"] * price}')
+				used_prices[mat['Ticker']] = price
+
+	print()
+	for ticker, price in used_prices.items():
+		print(f'{ticker:3}: {price}')
 
 def get_prices() -> typing.Mapping[str, float]:
 	cxos_users: typing.Mapping = cache.get('https://api.fnar.net/cx/cxos/?username=' + config.username,
@@ -38,7 +44,7 @@ def get_prices() -> typing.Mapping[str, float]:
 	prices: dict[str, float] = {}
 	for order in cxos:
 		if order['OrderType'] == 'BUYING' and order['Status'] == 'FILLED':
-			prices[order['MaterialTicker']] = order['LimitAmount']
+			prices.setdefault(order['MaterialTicker'], order['LimitAmount'])
 	return prices
 
 class Infrastructure(typing.TypedDict):