How to use the cassiopeia.data.Platform function in cassiopeia

To help you get started, we’ve selected a few cassiopeia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meraki-analytics / cassiopeia / cassiopeia / datastores / riotapi / champion.py View on Github external
from ..uniquekeys import convert_region_to_platform

T = TypeVar("T")


class ChampionAPI(RiotAPIService):
    @DataSource.dispatch
    def get(self, type: Type[T], query: MutableMapping[str, Any], context: PipelineContext = None) -> T:
        pass

    @DataSource.dispatch
    def get_many(self, type: Type[T], query: MutableMapping[str, Any], context: PipelineContext = None) -> Iterable[T]:
        pass

    _validate_get_champion_rotation_query = Query. \
        has("platform").as_(Platform)

    @get.register(ChampionRotationDto)
    @validate_query(_validate_get_champion_rotation_query, convert_region_to_platform)
    def get_champion_rotation(self, query: MutableMapping[str, Any], context: PipelineContext = None) -> ChampionRotationDto:
        url = "https://{platform}.api.riotgames.com/lol/platform/v3/champion-rotations".format(platform=query["platform"].value.lower())
        try:
            app_limiter, method_limiter = self._get_rate_limiter(query["platform"], "champion/rotations")
            data = self._get(url, {}, app_limiter=app_limiter, method_limiter=method_limiter)
        except APINotFoundError as error:
            raise NotFoundError(str(error)) from error

        data["platform"] = query["platform"].value
        data["region"] = query["platform"].region.value
        return ChampionRotationDto(**data)

    _validate_get_many_champion_rotation_query = Query. \
github meraki-analytics / cassiopeia / cassiopeia / plugins / diskstore / spectator.py View on Github external
pass

    @DataSink.dispatch
    def put(self, type: Type[T], item: T, context: PipelineContext = None) -> None:
        pass

    @DataSink.dispatch
    def put_many(self, type: Type[T], items: Iterable[T], context: PipelineContext = None) -> None:
        pass

    ##################
    # Featured Games #
    ##################

    _validate_get_featured_games_query = Query. \
        has("platform").as_(Platform)

    @get.register(FeaturedGamesDto)
    def get_featured_games(self, query: MutableMapping[str, Any], context: PipelineContext = None) -> FeaturedGamesDto:
        SpectatorDiskService._validate_get_featured_games_query(query, context)
        key = "{clsname}.{platform}".format(clsname=FeaturedGamesDto.__name__, platform=query["platform"].value)
        return FeaturedGamesDto(self._get(key))

    @put.register(FeaturedGamesDto)
    def put_featured_games(self, item: FeaturedGamesDto, context: PipelineContext = None) -> None:
        platform = Region(item["region"]).platform.value
        key = "{clsname}.{platform}".format(clsname=FeaturedGamesDto.__name__, platform=platform)
        self._put(key, item)

    ################
    # Current Game #
    ################
github meraki-analytics / cassiopeia / cassiopeia / datastores / uniquekeys.py View on Github external
def for_many_featured_games_dto_query(query: Query) -> Generator[str, None, None]:
    for platform in query["platforms"]:
        try:
            platform = Platform(platform)
            yield platform.value
        except ValueError as e:
            raise QueryValidationError from e
github meraki-analytics / cassiopeia / cassiopeia / datastores / riotapi / staticdata.py View on Github external
def generator():
            for platform in query["platforms"]:
                platform = Platform(platform.upper())
                url = "https://{platform}.api.riotgames.com/lol/static-data/v3/items".format(platform=platform.value.lower())
                try:
                    data = self._get(url, params, self._get_rate_limiter(platform, "staticdata/items"))
                except APINotFoundError as error:
                    raise NotFoundError(str(error)) from error

                data["region"] = platform.region.value
                data["locale"] = query["locale"] if "locale" in query else platform.default_locale
                data["includedData"] = query["includedData"]
                for key, item in data["data"].items():
                    item = ItemDto(item)
                    data["data"][key] = item
                    if item["id"] == 3632:  # This item doesn't have a name.
                        item["name"] = ""
                    if "tags" not in item:
                        item["tags"] = []
github meraki-analytics / cassiopeia / cassiopeia / datastores / riotapi / summoner.py View on Github external
class SummonerAPI(RiotAPIService):
    @DataSource.dispatch
    def get(self, type: Type[T], query: MutableMapping[str, Any], context: PipelineContext = None) -> T:
        pass

    @DataSource.dispatch
    def get_many(self, type: Type[T], query: MutableMapping[str, Any], context: PipelineContext = None) -> Iterable[T]:
        pass

    _validate_get_summoner_query = Query. \
        has("id").as_(str). \
        or_("accountId").as_(str). \
        or_("puuid").as_(str). \
        or_("name").as_(str).also. \
        has("platform").as_(Platform)

    @get.register(SummonerDto)
    @validate_query(_validate_get_summoner_query, convert_region_to_platform)
    def get_summoner(self, query: MutableMapping[str, Any], context: PipelineContext = None) -> SummonerDto:
        if "id" in query:
            url = "https://{platform}.api.riotgames.com/lol/summoner/v4/summoners/{summonerId}".format(platform=query["platform"].value.lower(), summonerId=query["id"])
            endpoint = "summoners/summonerId"
        elif "accountId" in query:
            url = "https://{platform}.api.riotgames.com/lol/summoner/v4/summoners/by-account/{accountId}".format(platform=query["platform"].value.lower(), accountId=query["accountId"])
            endpoint = "summoners/by-account/accountId"
        elif "name" in query:
            url = "https://{platform}.api.riotgames.com/lol/summoner/v4/summoners/by-name/{name}".format(platform=query["platform"].value.lower(), name=query["name"].replace(" ", "")).encode("utf-8")
            endpoint = "summoners/by-name/name"
        elif "puuid" in query:
            url = url = "https://{platform}.api.riotgames.com/lol/summoner/v4/summoners/by-puuid/{puuid}".format(platform=query["platform"].value.lower(), puuid=query["puuid"])
            endpoint = "summoners/by-puuid/puuid"
github meraki-analytics / cassiopeia / cassiopeia / datastores / riotapi / match.py View on Github external
data["accountId"] = query["account.id"]
        data["region"] = query["platform"].region.value
        data["season"] = seasons
        data["champion"] = champions
        data["queue"] = queues
        if calling_method == "by_index":
            data["beginIndex"] = params["beginIndex"]
            data["endIndex"] = params["endIndex"]
            data["maxNumberOfMatches"] = query["maxNumberOfMatches"]
        else:
            data["beginTime"] = params["beginTime"]
            data["endTime"] = params["endTime"]
        for match in data["matches"]:
            match["accountId"] = query["account.id"]
            match["region"] = Platform(match["platformId"]).region.value
        return MatchListDto(data)
github meraki-analytics / cassiopeia / cassiopeia / datastores / riotapi / staticdata.py View on Github external
def generator():
            for platform in query["platforms"]:
                platform = Platform(platform.upper())
                url = "https://{platform}.api.riotgames.com/lol/static-data/v3/profile-icons".format(platform=platform.value.lower())
                try:
                    data = self._get(url, params, self._get_rate_limiter(platform, "staticdata/profile-icons"))
                except APINotFoundError as error:
                    raise NotFoundError(str(error)) from error

                data["region"] = platform.region.value
                data["locale"] = query["locale"] if "locale" in query else platform.default_locale
                for pi in data["data"].values():
                    pi["region"] = data["region"]
                    pi["version"] = data["version"]
                    pi["locale"] = data["locale"]
                yield ProfileIconDataDto(data)
github meraki-analytics / cassiopeia / cassiopeia / datastores / riotapi / championmastery.py View on Github external
from ..uniquekeys import convert_region_to_platform

T = TypeVar("T")


class ChampionMasteryAPI(RiotAPIService):
    @DataSource.dispatch
    def get(self, type: Type[T], query: MutableMapping[str, Any], context: PipelineContext = None) -> T:
        pass

    @DataSource.dispatch
    def get_many(self, type: Type[T], query: MutableMapping[str, Any], context: PipelineContext = None) -> Iterable[T]:
        pass

    _validate_get_champion_mastery_query = Query. \
        has("platform").as_(Platform).also. \
        has("summoner.id").as_(str).also. \
        has("champion.id").as_(int)

    @get.register(ChampionMasteryDto)
    @validate_query(_validate_get_champion_mastery_query, convert_region_to_platform)
    def get_champion_mastery(self, query: MutableMapping[str, Any], context: PipelineContext = None) -> ChampionMasteryDto:
        url = "https://{platform}.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{summonerId}/by-champion/{championId}".format(platform=query["platform"].value.lower(), summonerId=query["summoner.id"], championId=query["champion.id"])
        try:
            endpoint = "champion-masteries/by-summoner/summonerId/by-champion/championId"
            app_limiter, method_limiter = self._get_rate_limiter(query["platform"], endpoint)
            data = self._get(url, {}, app_limiter=app_limiter, method_limiter=method_limiter)
        except APINotFoundError as error:
            raise NotFoundError(str(error)) from error

        data["region"] = query["platform"].region.value
        data["summonerId"] = query["summoner.id"]
github meraki-analytics / cassiopeia / cassiopeia / datastores / riotapi / staticdata.py View on Github external
def generator():
            for platform in query["platforms"]:
                platform = Platform(platform.upper())
                url = "https://{platform}.api.riotgames.com/lol/static-data/v3/languages".format(platform=platform.value.lower())
                try:
                    data = self._get(url, {}, self._get_rate_limiter(platform, "staticdata/language"))
                except APINotFoundError as error:
                    raise NotFoundError(str(error)) from error

                data["region"] = platform.region.value
                yield LanguagesDto(data)
github meraki-analytics / cassiopeia / cassiopeia / data.py View on Github external
Region.europe_west: "en_GB",
    Platform.europe_west: "en_GB",
    Region.japan: "ja_JP",
    Platform.japan: "ja_JP",
    Region.korea: "ko_KR",
    Platform.korea: "ko_KR",
    Region.latin_america_north: "es_MX",
    Platform.latin_america_north: "es_MX",
    Region.latin_america_south: "es_AR",
    Platform.latin_america_south: "es_AR",
    Region.north_america: "en_US",
    Platform.north_america: "en_US",
    Region.oceania: "en_AU",
    Platform.oceania: "en_AU",
    Region.turkey: "tr_TR",
    Platform.turkey: "tr_TR",
    Region.russia: "ru_RU",
    Platform.russia: "ru_RU",
}


class Key(Enum):
    Q = "Q"
    W = "W"
    E = "E"
    R = "R"


class Resource(Enum):
    mana = "Mana"
    courage = "Courage"
    energy = "Energy"