company.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from __future__ import annotations
  2. import collections
  3. import sys
  4. import typing
  5. import cache
  6. import integration
  7. def main() -> None:
  8. code = sys.argv[1]
  9. company: Company = cache.get('https://rest.fnar.net/company/code/' + code)
  10. planets = {cp['PlanetName'] for cp in company['Planets']}
  11. cogc_planets: dict[str, list[str]] = collections.defaultdict(list)
  12. for planet, cogc in iter_planet_cogc():
  13. if planet['PlanetName'] in planets:
  14. print(planet['PlanetName'], cogc, sep='\t\t')
  15. if cogc is not None:
  16. cogc_planets[cogc].append(planet['PlanetName'])
  17. buildings: typing.Sequence[Building] = cache.get('https://rest.fnar.net/building/allbuildings', expiry=cache.ONE_DAY)
  18. experts: dict[str, str] = {}
  19. for building in buildings:
  20. for recipe in building['Recipes']:
  21. for output in recipe['Outputs']:
  22. experts[output['CommodityTicker']] = building['Expertise']
  23. print()
  24. company_report = integration.pmmg_monthly_report()[company['CompanyId']]
  25. for mat in company_report.keys():
  26. expertise = experts.get(mat)
  27. print(mat, expertise, ', '.join(cogc_planets.get(expertise, []))) # pyright: ignore[reportArgumentType, reportCallIssue]
  28. def iter_planet_cogc() -> typing.Iterator[tuple[Planet, Expertise | None]]:
  29. all_planets: typing.Collection[Planet] = cache.get('https://universemap.taiyibureau.de/planet_data.json',
  30. expiry=cache.ONE_DAY)
  31. for planet in all_planets:
  32. cogc = None
  33. if len(cogcs := planet['COGCPrograms']) > 1:
  34. cogcs.sort(key=lambda c: c['StartEpochMs'], reverse=True)
  35. cogc = cogcs[1]['ProgramType']
  36. if cogc is not None:
  37. cogc = cogc.removeprefix('ADVERTISING_')
  38. yield planet, typing.cast(Expertise | None, cogc)
  39. Expertise = typing.Literal['AGRICULTURE', 'CHEMISTRY', 'CONSTRUCTION', 'ELECTRONICS', 'FOOD_INDUSTRIES',
  40. 'FUEL_REFINING', 'MANUFACTURING', 'METALLURGY', 'RESOURCE_EXTRACTION']
  41. class Company(typing.TypedDict):
  42. CompanyId: str
  43. Planets: typing.Sequence[CompanyPlanet]
  44. class CompanyPlanet(typing.TypedDict):
  45. PlanetNaturalId: str
  46. PlanetName: str
  47. class Planet(typing.TypedDict):
  48. PlanetId: str
  49. PlanetName: str
  50. COGCPrograms: list[PlanetCOGC]
  51. class PlanetCOGC(typing.TypedDict):
  52. ProgramType: str | None
  53. StartEpochMs: float
  54. class Building(typing.TypedDict):
  55. Recipes: typing.Sequence[BuildingRecipe]
  56. Expertise: str
  57. class BuildingRecipe(typing.TypedDict):
  58. Outputs: typing.Sequence[BuildingMat]
  59. class BuildingMat(typing.TypedDict):
  60. CommodityTicker: str
  61. Amount: int
  62. if __name__ == '__main__':
  63. main()