-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,047 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class AbstractLocalMarket: | ||
# /localmarket/{LocalMarketId} | ||
def get(self, localmarket_id: str): | ||
raise NotImplementedError() | ||
|
||
# /localmarket/planet/{Planet} | ||
def planet(self, planet: str): | ||
raise NotImplementedError() | ||
|
||
# /localmarket/planet/{Planet}/{Type} | ||
def planet_type(self, planet: str, type: str): | ||
raise NotImplementedError() | ||
|
||
# /localmarket/shipping/source/{SourcePlanet} | ||
def shipping_from(self, planet: str): | ||
raise NotImplementedError() | ||
|
||
# /localmarket/shipping/destination/{DestinationPlanet} | ||
def shipping_to(self, planet: str): | ||
raise NotImplementedError() | ||
|
||
# /localmarket/company/{Company} | ||
def company(self, companycode: str): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class AbstractPlanet: | ||
def get(self, planet: str): | ||
raise NotImplementedError() | ||
|
||
def all(self): | ||
raise NotImplementedError() | ||
|
||
def full(self): | ||
raise NotImplementedError() | ||
|
||
def sites(self, planet: str): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,80 @@ | ||
from pyfio.endpoints.abstracts.abstract_planet import AbstractPlanet | ||
from pyfio.exceptions import PlanetNotFound | ||
from pyfio.fio_adapter import FIOAdapter | ||
from pyfio.models.planet_models import ( | ||
PlanetFull, | ||
PlanetFullList, | ||
PlanetList, | ||
PlanetSiteList, | ||
) | ||
|
||
|
||
class Planet: | ||
class Planet(AbstractPlanet): | ||
def __init__(self, adapter: FIOAdapter) -> None: | ||
self._adapter: FIOAdapter = adapter | ||
|
||
# /planet/{Planet} | ||
def get(self, planet: str) -> PlanetFull: | ||
"""Gets full planet data from FIO | ||
Args: | ||
planet (str): PlanetId, PlanetNaturalId or PlanetName | ||
Raises: | ||
PlanetNotFound: Planet not found | ||
Returns: | ||
PlanetFull: Full planet information | ||
""" | ||
(status, data) = self._adapter.get( | ||
endpoint=self._adapter.urls.planet_get_url(planet=planet) | ||
) | ||
|
||
if status == 200: | ||
return PlanetFull.model_validate(data) | ||
elif status == 204: | ||
raise PlanetNotFound("Planet not found") | ||
|
||
# /planet/allplanets | ||
def all(self) -> PlanetList: | ||
"""Gets a list of all Planets with minimal information from FIO | ||
Returns: | ||
PlanetList: List of Planets as List[Planet] | ||
""" | ||
(_, data) = self._adapter.get(endpoint=self._adapter.urls.planet_all_url()) | ||
|
||
return PlanetList.model_validate(data) | ||
|
||
# /planet/allplanets/full | ||
# /planet/{Planet} | ||
def full(self) -> PlanetFullList: | ||
"""Gets a list of all planets from FIO with full planet information | ||
Returns: | ||
PlanetFullList: List of Planets with full information as List[PlanetFull] | ||
""" | ||
(_, data) = self._adapter.get(endpoint=self._adapter.urls.planet_full_url()) | ||
|
||
return PlanetFullList.model_validate(data) | ||
|
||
# /planet/sites/{Planet} | ||
# /planet/sitescount/{Planet} | ||
def sites(self, planet: str) -> PlanetSiteList: | ||
"""Gets a list of sites on the planet from FIO | ||
Args: | ||
planet (str): PlanetId, PlanetNaturalId or PlanetName | ||
Raises: | ||
PlanetNotFound: Planet not found | ||
Returns: | ||
PlanetSiteList: List of Planet sites as List[PlanetSite] | ||
""" | ||
(status, data) = self._adapter.get( | ||
endpoint=self._adapter.urls.planet_sites_url(planet=planet) | ||
) | ||
|
||
if status == 200: | ||
return PlanetSiteList.model_validate(data) | ||
elif status == 204: | ||
raise PlanetNotFound("Planet not found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
from typing import List, Optional | ||
from pydantic import BaseModel, RootModel, Field, NaiveDatetime | ||
from datetime import datetime | ||
|
||
|
||
class PlanetResource(BaseModel): | ||
MaterialId: str = Field(min_length=32) | ||
ResourceType: str | ||
Factor: float | ||
|
||
|
||
class BuildingRequirement(BaseModel): | ||
MaterialName: str | ||
MaterialId: str = Field(min_length=32) | ||
MaterialTicker: str = Field(max_length=3) | ||
MaterialCategory: str = Field(min_length=32) | ||
MaterialAmount: int | ||
MaterialWeight: float | ||
MaterialVolume: float | ||
|
||
|
||
class ProductionFee(BaseModel): | ||
Category: str | ||
WorkforceLevel: str | ||
FeeAmount: int | ||
FeeCurrency: Optional[str] | ||
|
||
|
||
class COGCProgram(BaseModel): | ||
ProgramType: Optional[str] | ||
StartEpochMs: datetime | ||
EndEpochMs: datetime | ||
|
||
|
||
class COGCVote(BaseModel): | ||
CompanyName: str | ||
CompanyCode: str | ||
Influence: float | ||
VoteType: str | ||
VoteTimeEpochMs: datetime | ||
|
||
|
||
class Planet(BaseModel): | ||
PlanetNaturalId: str | ||
PlanetName: str | ||
|
||
|
||
class PlanetList(RootModel): | ||
root: List[Planet] | ||
|
||
def __iter__(self): | ||
return iter(self.root) | ||
|
||
|
||
class PlanetFull(Planet): | ||
Resources: List[PlanetResource] | ||
BuildRequirements: List[BuildingRequirement] | ||
ProductionFees: List[ProductionFee] | ||
COGCPrograms: List[COGCProgram] | ||
COGCVotes: List[COGCVote] | ||
|
||
PlanetId: str = Field(min_length=32) | ||
Namer: Optional[str] | ||
NamingDataEpochMs: int | ||
Nameable: bool | ||
SystemId: str = Field(min_length=32) | ||
Gravity: float | ||
MagneticField: float | ||
Mass: float | ||
MassEarth: float | ||
OrbitSemiMajorAxis: int | ||
OrbitEccentricity: float | ||
OrbitInclination: float | ||
OrbitRightAscension: int | ||
OrbitPeriapsis: int | ||
OrbitIndex: int | ||
Pressure: float | ||
Radiation: float | ||
Radius: float | ||
Sunlight: float | ||
Surface: bool | ||
Temperature: float | ||
Fertility: float | ||
HasLocalMarket: bool | ||
HasChamberOfCommerce: bool | ||
HasWarehouse: bool | ||
HasAdministrationCenter: bool | ||
HasShipyard: bool | ||
FactionCode: Optional[str] | ||
FactionName: Optional[str] | ||
GovernorId: Optional[str] = Field(min_length=32) | ||
GovernorUserName: Optional[str] | ||
GovernorCorporationId: Optional[str] = Field(min_length=32) | ||
GovernorCorporationName: Optional[str] | ||
GovernorCorporationCode: Optional[str] | ||
CurrencyName: Optional[str] | ||
CurrencyCode: Optional[str] | ||
CollectorId: Optional[str] = Field(min_length=32) | ||
CollectorName: Optional[str] | ||
CollectorCode: Optional[str] | ||
BaseLocalMarketFee: int | ||
LocalMarketFeeFactor: int | ||
WarehouseFee: int | ||
PopulationId: Optional[str] = Field(min_length=32) | ||
COGCProgramStatus: Optional[str] | ||
PlanetTier: int | ||
UserNameSubmitted: str | ||
Timestamp: NaiveDatetime | ||
|
||
|
||
class PlanetFullList(RootModel): | ||
root: List[PlanetFull] | ||
|
||
def __iter__(self): | ||
return iter(self.root) | ||
|
||
|
||
class PlanetSite(BaseModel): | ||
PlanetId: str = Field(min_length=32) | ||
OwnerId: str = Field(min_length=32) | ||
OwnerName: str | ||
OwnerCode: Optional[str] | ||
PlotNumber: int | ||
PlotId: str = Field(min_length=32) | ||
SiteId: str | ||
|
||
|
||
class PlanetSiteList(RootModel): | ||
root: List[PlanetSite] | ||
|
||
def __iter__(self): | ||
return iter(self.root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.