polytoria.py 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polyapi/__init__.py +3 -0
- polyapi/api_client.py +22 -0
- polyapi/models.py +112 -0
- polyapi/wrapper.py +30 -0
- polytoria_py-0.1.0.dist-info/METADATA +6 -0
- polytoria_py-0.1.0.dist-info/RECORD +8 -0
- polytoria_py-0.1.0.dist-info/WHEEL +5 -0
- polytoria_py-0.1.0.dist-info/top_level.txt +1 -0
polyapi/__init__.py
ADDED
polyapi/api_client.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from curl_cffi.requests import AsyncSession
|
|
2
|
+
|
|
3
|
+
class APIClient:
|
|
4
|
+
def __init__(self, browser: str = "chrome", base_url:str = None):
|
|
5
|
+
self.base_url = base_url or "https://api.polytoria.com/v1"
|
|
6
|
+
self.browser = browser
|
|
7
|
+
|
|
8
|
+
async def fetch_data(self, endpoint:str, base_url:str = None, params: dict = None) -> dict:
|
|
9
|
+
url = f"{self.base_url}/{endpoint}"
|
|
10
|
+
print(url)
|
|
11
|
+
|
|
12
|
+
async with AsyncSession(impersonate=self.browser) as session:
|
|
13
|
+
try:
|
|
14
|
+
response = await session.get(
|
|
15
|
+
url,
|
|
16
|
+
params=params,
|
|
17
|
+
)
|
|
18
|
+
response.raise_for_status()
|
|
19
|
+
return response.json()
|
|
20
|
+
except Exception as e:
|
|
21
|
+
print(f"API Request failed: {e}")
|
|
22
|
+
raise
|
polyapi/models.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from src.api_client import APIClient
|
|
2
|
+
|
|
3
|
+
class User:
|
|
4
|
+
def __init__(self, data:dict, client):
|
|
5
|
+
self.client = client
|
|
6
|
+
|
|
7
|
+
self.id = data.get("id")
|
|
8
|
+
self.username = data.get("username")
|
|
9
|
+
self.description = data.get("description")
|
|
10
|
+
self.thumbnail = data.get("thumbnail")
|
|
11
|
+
if isinstance(self.thumbnail, dict):
|
|
12
|
+
self.avatar = self.thumbnail.get("avatar")
|
|
13
|
+
self.icon = self.thumbnail.get("icon")
|
|
14
|
+
else:
|
|
15
|
+
self.avatar = None
|
|
16
|
+
self.icon = None
|
|
17
|
+
self.playing = data.get("playing")
|
|
18
|
+
self.networth = data.get("netWorth")
|
|
19
|
+
self.placevisits = data.get("placeVisits")
|
|
20
|
+
self.forumposts = data.get("forumPosts")
|
|
21
|
+
self.assetSales = data.get("assetSales")
|
|
22
|
+
self.membershipType = data.get("membershipType")
|
|
23
|
+
self.istaff = data.get("isStaff")
|
|
24
|
+
self.userroleclass = data.get("userRoleClass")
|
|
25
|
+
self.joindate = data.get("registeredAt")
|
|
26
|
+
self.lastseen = data.get("lastSeenAt")
|
|
27
|
+
|
|
28
|
+
def __repr__(self): # used for debugging
|
|
29
|
+
return f"id={self.id} username={self.username} description={self.description}"
|
|
30
|
+
|
|
31
|
+
class Item:
|
|
32
|
+
def __init__(self, data:dict, client):
|
|
33
|
+
self.client = client
|
|
34
|
+
|
|
35
|
+
self.id = data.get("id")
|
|
36
|
+
self.type = data.get("type")
|
|
37
|
+
self.accessorytype = data.get("accessoryType")
|
|
38
|
+
self.name = data.get("name")
|
|
39
|
+
self.description = data.get("description")
|
|
40
|
+
self.tags = data.get("tags", []) or []
|
|
41
|
+
self.creator = data["creator"]["name"]
|
|
42
|
+
self.thumbnail = data.get("thumbnail")
|
|
43
|
+
self.price = data.get("price")
|
|
44
|
+
self.studprice = data.get("priceInStuds")
|
|
45
|
+
self.averageprice = data.get("averagePrice")
|
|
46
|
+
self.version = data.get("version")
|
|
47
|
+
self.sales = data.get("sales")
|
|
48
|
+
self.favorites = data.get("favorites")
|
|
49
|
+
|
|
50
|
+
self._owners = None
|
|
51
|
+
|
|
52
|
+
async def owners(self):
|
|
53
|
+
if self._owners == None:
|
|
54
|
+
self._owners = await self.client.fetch_data(f"store/{self.id}/owners", base_url="https://api.polytoria.com/v1/")
|
|
55
|
+
return self._owners
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def __repr__(self):
|
|
59
|
+
return f"id={self.id} name={self.name} description={self.description}"
|
|
60
|
+
|
|
61
|
+
class Place: # /api/places /v1/api/places/{id}
|
|
62
|
+
def __init__(self, data:dict, client):
|
|
63
|
+
self.client = client
|
|
64
|
+
|
|
65
|
+
self.id = data.get("id")
|
|
66
|
+
self.name = data.get("name")
|
|
67
|
+
self.description = data.get("description")
|
|
68
|
+
self.creator = data["creator"]["name"]
|
|
69
|
+
self.thumbnail = data.get("thumbnail")
|
|
70
|
+
self.genre = data.get("genre")
|
|
71
|
+
self.maxplayers = data.get("maxPlayers")
|
|
72
|
+
self.isactive = data.get("isActive")
|
|
73
|
+
self.istoolsenabled = data.get("isToolsEnabled")
|
|
74
|
+
self.iscopyable = data.get("isCopyable")
|
|
75
|
+
self.visits = data.get("visits")
|
|
76
|
+
self.uniquevisits = data.get("uniqueVisits")
|
|
77
|
+
self.playing = data.get("playing")
|
|
78
|
+
self.rating = data.get("rating")
|
|
79
|
+
self.accesstype = data.get("accessType")
|
|
80
|
+
self.accessprice = data.get("accessPrice")
|
|
81
|
+
self.createdat = data.get("createdAt")
|
|
82
|
+
self.updatedat = data.get("updatedAt")
|
|
83
|
+
|
|
84
|
+
def __repr__(self):
|
|
85
|
+
return f""
|
|
86
|
+
|
|
87
|
+
class Guild: # /api/guilds/{id} /v1/guilds/{id}
|
|
88
|
+
def __init__(self, data:dict, client):
|
|
89
|
+
self.client = client
|
|
90
|
+
|
|
91
|
+
self.id = data.get("id")
|
|
92
|
+
self.name = data.get("name")
|
|
93
|
+
self.description = data.get("description")
|
|
94
|
+
self.creator = data["creator"]["name"]
|
|
95
|
+
self.thumbnail = data.get("thumbnail")
|
|
96
|
+
self.banner = data.get("banner")
|
|
97
|
+
self.color = data.get("color")
|
|
98
|
+
self.jointype = data.get("joinType")
|
|
99
|
+
self.membercount = data.get("memberCount")
|
|
100
|
+
self.vaultbalance = data.get("vaultBalance")
|
|
101
|
+
self.isverified = data.get("isVerified")
|
|
102
|
+
self.createdat = data.get("createdAt")
|
|
103
|
+
|
|
104
|
+
def __repr__(self):
|
|
105
|
+
return f""
|
|
106
|
+
|
|
107
|
+
class Forum: # /v1/forum
|
|
108
|
+
def __init__(self, data:dict, client):
|
|
109
|
+
self.client = client
|
|
110
|
+
|
|
111
|
+
def __repr__(self):
|
|
112
|
+
return f""
|
polyapi/wrapper.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from src.api_client import APIClient
|
|
2
|
+
from src.models import User, Item, Place, Guild
|
|
3
|
+
|
|
4
|
+
class Polytoria:
|
|
5
|
+
def __init__(self, browser: str = "chrome"):
|
|
6
|
+
self._client = APIClient(browser=browser)
|
|
7
|
+
|
|
8
|
+
async def user(self, user_id: int) -> User:
|
|
9
|
+
|
|
10
|
+
raw_data = await self._client.fetch_data(f"users/{user_id}", base_url="https://api.polytoria.com/v1/")
|
|
11
|
+
|
|
12
|
+
return User(raw_data, self._client)
|
|
13
|
+
|
|
14
|
+
async def item(self, item_id: int) -> Item:
|
|
15
|
+
|
|
16
|
+
raw_data = await self._client.fetch_data(f"store/{item_id}", base_url="https://api.polytoria.com/v1/")
|
|
17
|
+
|
|
18
|
+
return Item(raw_data, self._client)
|
|
19
|
+
|
|
20
|
+
async def place(self, place_id: int) -> Place:
|
|
21
|
+
|
|
22
|
+
raw_data = await self._client.fetch_data(f"places/{place_id}", base_url="https://api.polytoria.com/v1/")
|
|
23
|
+
|
|
24
|
+
return Place(raw_data, self._client)
|
|
25
|
+
|
|
26
|
+
async def guild(self, guild_id: int) -> Guild:
|
|
27
|
+
|
|
28
|
+
raw_data = await self._client.fetch_data(f"guilds/{guild_id}", base_url="https://api.polytoria.com/v1/")
|
|
29
|
+
|
|
30
|
+
return Place(raw_data, self._client)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
polyapi/__init__.py,sha256=tjUNjfyl4InCzvlPcDkMFq-3eaGnCtmvI5v36emnns8,57
|
|
2
|
+
polyapi/api_client.py,sha256=jl4wfe5OCN3kMTU_5oE-IUFp-pAYlq6FmcQOiyjoKzs,812
|
|
3
|
+
polyapi/models.py,sha256=EpI3x6WWXShIieomVCglBrUt9uaMfJPzbSiFtM-NogI,4165
|
|
4
|
+
polyapi/wrapper.py,sha256=0GpoHASA4KLUdq8KBcyRBQ0JSfeKQdBt9--c4dseQJA,1114
|
|
5
|
+
polytoria_py-0.1.0.dist-info/METADATA,sha256=j5-ocBKYds_5SfDYpdaM23I4xkh5RAclFDxvdQWWOY4,150
|
|
6
|
+
polytoria_py-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
polytoria_py-0.1.0.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
|
|
8
|
+
polytoria_py-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
polyapi
|