Skip to content

Commit

Permalink
Added Account XP info class
Browse files Browse the repository at this point in the history
  • Loading branch information
akex06 committed Apr 2, 2024
1 parent 36876e6 commit 6ba3f11
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 18 deletions.
2 changes: 1 addition & 1 deletion valorant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from valorant.valorant import Valorant
from valorant.classes import Agent, Ability, Role, LockFile, Agents, Version, User
from valorant.classes import Agent, Ability, Role, LockFile, Agents, Version, User, AccountXP
from valorant.constants import Region, Regions
from valorant.xmpp import XMPP
93 changes: 86 additions & 7 deletions valorant/classes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
import os
from typing import Self
from typing import Self, Literal

import requests

Expand Down Expand Up @@ -189,7 +189,7 @@ def __init__(
name: str,
description: str,
display_icon: str
):
) -> None:
self.id = _id
self.name = name
self.description = description
Expand All @@ -210,7 +210,7 @@ def __init__(
slot: int,
description: str,
display_icon: str
):
) -> None:
self.name = name
self.slot = slot
self.description = description
Expand Down Expand Up @@ -247,7 +247,7 @@ def __init__(
colors: list[str],
role: Role,
abilities: list[Ability]
):
) -> None:
self.id = _id
self.name = name
self.description = description
Expand All @@ -267,7 +267,7 @@ def from_uuid(cls, uuid: str):


class Agents:
def __init__(self):
def __init__(self) -> None:
agent_list = requests.get("https://valorant-api.com/v1/agents/").json()["data"]
agents = {agent["uuid"]: agent for agent in agent_list}

Expand Down Expand Up @@ -319,7 +319,7 @@ def __init__(
riot_client_version: str,
riot_client_build: str,
build_date: str
):
) -> None:
self.manifest_id = manifest_id
self.branch = branch
self.version = version
Expand Down Expand Up @@ -358,7 +358,7 @@ def __init__(
player_locale: str | None,
acct: dict,
jti: str,
):
) -> None:
self.country = country
self.player_id = player_id
self.is_email_verified = is_email_verified
Expand All @@ -370,3 +370,82 @@ def __init__(
self.player_locale = player_locale
self.acct = acct
self.jti = jti


class Progress(APIConverter):
mapping = {
"Level": "level",
"XP": "xp"
}

def __init__(self, level: int, xp: int) -> None:
self.level = level
self.xp = xp


class XPSource(APIConverter):
mapping = {
"ID": "_id",
"Amount": "amount"
}

def __init__(self, _id: Literal["time-played", "match-win", "first-win-of-the-day"], amount: int) -> None:
self.id = _id
self.amount = amount


class MatchDetails(APIConverter):
mapping = {
"ID": "_id",
"MatchStart": "start",
"StartProgress": ("start_progress", Progress),
"EndProgress": ("end_progress", Progress),
"XPDelta": "xp_delta",
"XPSources": ("xp_sources", XPSource),
"XPMultipliers": "xp_multipliers"
}

def __init__(
self,
_id: str,
start: str,
start_progress: Progress,
end_progress: Progress,
xp_delta: int,
xp_sources: XPSource,
xp_multiplier: list,
) -> None:
self._id = _id
self.start = start
self.start_progress = start_progress
self.end_progress = end_progress
self.xp_delta = xp_delta
self.xp_sources = xp_sources
self.xp_multiplier = xp_multiplier


class AccountXP(APIConverter):
mapping = {
"Version": "version",
"Subject": "player_id",
"Progress": ("progress", Progress),
"History": ("history", MatchDetails),
"LastTimeGrantedFirstWin": "last_time_granted_first_win",
"NextTimeFirstWinAvailable": "next_time_first_win_available"
}

def __init__(
self,
version: int,
player_id: str,
progress: Progress,
history: list[MatchDetails],
last_time_granted_first_win: str,
next_time_first_win_available: str,
) -> None:
self.version = version
self.player_id = player_id
self.progress = progress
self.history = history
self.last_time_granted_first_win = last_time_granted_first_win
self.next_time_first_win_available = next_time_first_win_available
21 changes: 11 additions & 10 deletions valorant/valorant.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
import urllib3

from valorant.classes import Auth, Version, User
from valorant.classes import Auth, Version, User, AccountXP
from valorant.constants import URLS, API, Region, regions

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
Expand Down Expand Up @@ -61,7 +61,6 @@ def get_user(self) -> User:
},
json={}
).json()
print(user_info)
return User.from_api_output(user_info)

def get_region(self) -> Region:
Expand All @@ -88,14 +87,16 @@ def get_content(self) -> dict:
}
).json()

def get_account_xp(self) -> dict:
return self.session.get(
f"{self.pd_server}{API.ACCOUNT_XP}/{self.user_info.player_id}",
headers={
"X-Riot-Entitlements-JWT": self.auth.get_entitlement_token(),
"Authorization": f"Bearer {self.auth.get_access_token()}"
}
).json()
def get_account_xp(self) -> AccountXP:
return AccountXP.from_api_output(
self.session.get(
f"{self.pd_server}{API.ACCOUNT_XP}/{self.user_info.player_id}",
headers={
"X-Riot-Entitlements-JWT": self.auth.get_entitlement_token(),
"Authorization": f"Bearer {self.auth.get_access_token()}"
}
).json()
)

def get_loadout(self) -> dict:
return self.session.get(
Expand Down

0 comments on commit 6ba3f11

Please sign in to comment.