company.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from __future__ import annotations
  2. import collections
  3. import concurrent.futures
  4. import sys
  5. import typing
  6. import cache
  7. import integration
  8. def main() -> None:
  9. code = sys.argv[1]
  10. company: Company = cache.get('https://rest.fnar.net/company/code/' + code)
  11. cogc_planets: dict[str, list[str]] = collections.defaultdict(list)
  12. with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
  13. futures: list[concurrent.futures.Future[Planet]] = [
  14. executor.submit(cache.get, 'https://rest.fnar.net/planet/' + planet['PlanetNaturalId'])
  15. for planet in company['Planets']]
  16. for future in futures:
  17. planet = future.result()
  18. cogc = None
  19. cogcs = planet['COGCPrograms']
  20. if len(cogcs) > 1:
  21. cogcs.sort(key=lambda c: c['StartEpochMs'], reverse=True)
  22. cogc = cogcs[1]['ProgramType']
  23. if cogc is not None:
  24. cogc = cogc.removeprefix('ADVERTISING_')
  25. print(planet['PlanetName'], cogc)
  26. if cogc is not None:
  27. cogc_planets[cogc].append(planet['PlanetName'])
  28. buildings: typing.Sequence[Building] = cache.get('https://rest.fnar.net/building/allbuildings')
  29. experts: dict[str, str] = {}
  30. for building in buildings:
  31. for recipe in building['Recipes']:
  32. for output in recipe['Outputs']:
  33. experts[output['CommodityTicker']] = building['Expertise']
  34. print()
  35. company_report = integration.pmmg_monthly_report()[company['CompanyId']]
  36. for mat in company_report.keys():
  37. expertise = experts.get(mat)
  38. print(mat, expertise, ', '.join(cogc_planets.get(expertise, []))) # pyright: ignore[reportArgumentType, reportCallIssue]
  39. class Company(typing.TypedDict):
  40. CompanyId: str
  41. Planets: typing.Sequence[CompanyPlanet]
  42. class CompanyPlanet(typing.TypedDict):
  43. PlanetNaturalId: str
  44. class Planet(typing.TypedDict):
  45. PlanetId: str
  46. PlanetName: str
  47. COGCPrograms: list[PlanetCOGC]
  48. class PlanetCOGC(typing.TypedDict):
  49. ProgramType: str | None
  50. StartEpochMs: float
  51. class Building(typing.TypedDict):
  52. Recipes: typing.Sequence[BuildingRecipe]
  53. Expertise: str
  54. class BuildingRecipe(typing.TypedDict):
  55. Outputs: typing.Sequence[BuildingMat]
  56. class BuildingMat(typing.TypedDict):
  57. CommodityTicker: str
  58. Amount: int
  59. if __name__ == '__main__':
  60. main()