import sys import typing import httpx import cache from config import config import integration def main() -> None: stats_month = integration.pmmg_month() coid_totals = integration.pmmg_monthly_report()['totals'] bases = cache.get(f'https://prun.raylu.net/stats/data/base-data-{stats_month}.json', expiry=cache.ONE_DAY) for co in iter_grants(): if co is None: print('\n') continue company = cache.get('https://rest.fnar.net/company/code/' + co) co_id = company['CompanyId'] username = company['UserName'] try: url = 'https://prun.raylu.net/stats/?type=compTotals&chartType=treemap&metric=volume&group=company&companyName=' + username print(f'\t{bases[co_id]["bases"]} bases\t{coid_totals[co_id]["volume"]:,.0f} volume\t{url}\n') except KeyError: print(f'\tno stats for {username}\n') def iter_grants() -> typing.Iterator[str | 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']) yield contract['PartnerCode'] if len(data['Contracts']) < 200: break params['page'] += 1 if __name__ == '__main__': main()