raylu 3 дней назад
Родитель
Сommit
8e354216f5
2 измененных файлов с 37 добавлено и 1 удалено
  1. 2 1
      punoted/contracts.py
  2. 35 0
      punoted/grants.py

+ 2 - 1
punoted/contracts.py

@@ -28,7 +28,8 @@ def main() -> None:
 				case 'PAYMENT':
 					print('\t', condition['Amount'], condition['Currency'])
 				case 'PROVISION_SHIPMENT' | 'PICKUP_SHIPMENT' | 'DELIVERY_SHIPMENT' | 'REPUTATION' | 'EXPLORATION' | 'REPAIR_SHIP' \
-						| 'PROVISION' | 'LOAN_PAYOUT' | 'LOAN_INSTALLMENT':
+						| 'PROVISION' | 'LOAN_PAYOUT' | 'LOAN_INSTALLMENT' | 'WORKFORCE_PROGRAM_PAYMENT' | 'WORKFORCE_PROGRAM_START' \
+						| 'CONSTRUCT_SHIP':
 					pass
 				case _:
 					raise AssertionError('unhandled condition type ' + condition['Type'])

+ 35 - 0
punoted/grants.py

@@ -0,0 +1,35 @@
+import sys
+
+import httpx
+
+from config import config
+
+def main() -> None:
+	(username,) = sys.argv[1:]
+	params = {'username': username, 'status': 'TERMINATED', 'limit': 200, 'page': 1}
+	while True:
+		(data,) = httpx.get(f'https://api.punoted.net/v1/contracts/?username={username}&limit=200', params=params,
+				headers={'X-Data-Token': config.punoted_api_key}).raise_for_status().json()
+		data['Contracts'].sort(key=lambda c: c['DateEpochMs'])
+		for contract in data['Contracts']:
+			conditions = contract['Conditions']
+			if len(conditions) != 2:
+				continue
+			payment = None
+			if conditions[0]['Type'] == 'PAYMENT' and conditions[1]['Type'] == 'DELIVERY':
+				payment, delivery = conditions
+				if payment['Amount'] < 100000 or payment['Amount'] > 1000000 or delivery['Address'] != 'JY-313f (JY-313)':
+					continue
+			elif conditions[0]['Type'] == 'LOAN_PAYOUT' and conditions[1]['Type'] == 'LOAN_INSTALLMENT':
+				payment, installment = conditions
+				if payment['Amount'] < 100000 or payment['Amount'] > 1000000:
+					continue
+			if payment is not None and payment['Status'] == 'FULFILLED':
+				print(f'{payment["Amount"]:9,} {payment["Currency"]}', contract['Status'], contract['Timestamp'],
+						contract['PartnerCode'], contract['PartnerName'])
+		if len(data['Contracts']) < 200:
+			break
+		params['page'] += 1
+
+if __name__ == '__main__':
+	main()