|
@@ -12,16 +12,24 @@ def main() -> None:
|
|
|
fio_api_key = config['fio_api_key']
|
|
fio_api_key = config['fio_api_key']
|
|
|
|
|
|
|
|
with open('www/data/knownCompanies.json', 'r') as f:
|
|
with open('www/data/knownCompanies.json', 'r') as f:
|
|
|
- companies = json.load(f)
|
|
|
|
|
|
|
+ companies: dict = json.load(f)
|
|
|
|
|
+ usernames = {co['Username'].casefold(): co_id for co_id, co in companies.items() if co['Username'] is not None}
|
|
|
|
|
|
|
|
- all_companies: typing.Collection[FIOCompany] = httpx.get('https://rest.fnar.net/company/all',
|
|
|
|
|
|
|
+ all_companies: list[FIOCompany] = httpx.get('https://rest.fnar.net/company/all',
|
|
|
headers={'Authorization': fio_api_key}).raise_for_status().json()
|
|
headers={'Authorization': fio_api_key}).raise_for_status().json()
|
|
|
|
|
+ all_companies.sort(key=lambda co: co['Timestamp']) # duplicate usernames appear due to COLIQs
|
|
|
try:
|
|
try:
|
|
|
for company in all_companies:
|
|
for company in all_companies:
|
|
|
username = company['UserName']
|
|
username = company['UserName']
|
|
|
if username is None:
|
|
if username is None:
|
|
|
print(company['CompanyId'], 'has no username:', company)
|
|
print(company['CompanyId'], 'has no username:', company)
|
|
|
continue
|
|
continue
|
|
|
|
|
+
|
|
|
|
|
+ old_co_id = usernames.get(username.casefold())
|
|
|
|
|
+ if old_co_id is not None and old_co_id != company['CompanyId']:
|
|
|
|
|
+ print(username, 'previously known as', old_co_id)
|
|
|
|
|
+ companies.pop(old_co_id, None)
|
|
|
|
|
+
|
|
|
known_company = {'Username': username}
|
|
known_company = {'Username': username}
|
|
|
if corp := company.get('CorporationCode'):
|
|
if corp := company.get('CorporationCode'):
|
|
|
known_company['Corporation'] = corp
|
|
known_company['Corporation'] = corp
|
|
@@ -39,6 +47,7 @@ class FIOCompany(typing.TypedDict):
|
|
|
CompanyId: str
|
|
CompanyId: str
|
|
|
UserName: str | None
|
|
UserName: str | None
|
|
|
CorporationCode: str | None
|
|
CorporationCode: str | None
|
|
|
|
|
+ Timestamp: str
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
main()
|
|
main()
|