Bladeren bron

handle COLIQed companies

raylu 1 maand geleden
bovenliggende
commit
f26278dbef
2 gewijzigde bestanden met toevoegingen van 11 en 2 verwijderingen
  1. 11 2
      py/update_companies.py
  2. 0 0
      www/data/knownCompanies.json

+ 11 - 2
py/update_companies.py

@@ -12,16 +12,24 @@ def main() -> None:
 	fio_api_key = config['fio_api_key']
 
 	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()
+	all_companies.sort(key=lambda co: co['Timestamp']) # duplicate usernames appear due to COLIQs
 	try:
 		for company in all_companies:
 			username = company['UserName']
 			if username is None:
 				print(company['CompanyId'], 'has no username:', company)
 				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}
 			if corp := company.get('CorporationCode'):
 				known_company['Corporation'] = corp
@@ -39,6 +47,7 @@ class FIOCompany(typing.TypedDict):
 	CompanyId: str
 	UserName: str | None
 	CorporationCode: str | None
+	Timestamp: str
 
 if __name__ == '__main__':
 	main()

File diff suppressed because it is too large
+ 0 - 0
www/data/knownCompanies.json


Some files were not shown because too many files changed in this diff