Kaynağa Gözat

just take the most recent company ID

FIO seems to keep old data around forever
so there's no need to incrementally from the old known companies
raylu 1 ay önce
ebeveyn
işleme
e39bb77097
2 değiştirilmiş dosya ile 20 ekleme ve 28 silme
  1. 20 28
      py/update_companies.py
  2. 0 0
      www/data/knownCompanies.json

+ 20 - 28
py/update_companies.py

@@ -11,37 +11,29 @@ def main() -> None:
 		config = tomllib.load(f)
 	fio_api_key = config['fio_api_key']
 
-	with open('www/data/knownCompanies.json', 'r') as 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: 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
-
-			if known_company == companies.get(company['CompanyId']):
-				print(username, 'had no change')
-			else:
-				print(known_company)
-				companies[company['CompanyId']] = known_company
-	finally:
-		with open('www/data/knownCompanies.json', 'w') as f:
-			json.dump(companies, f)
+	all_companies.sort(key=lambda co: co['Timestamp'], reverse=True) # duplicate usernames appear due to COLIQs
+
+	usernames = set()
+	companies = {}
+	for company in all_companies:
+		username = company['UserName']
+		if username is None:
+			continue
+		if username in usernames:
+			continue
+		else:
+			usernames.add(username)
+
+		known_company = {'Username': username}
+		if corp := company.get('CorporationCode'):
+			known_company['Corporation'] = corp
+		companies[company['CompanyId']] = known_company
+
+	with open('www/data/knownCompanies.json', 'w') as f:
+		json.dump(companies, f)
 
 class FIOCompany(typing.TypedDict):
 	CompanyId: str

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
www/data/knownCompanies.json


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor