lpdb_python 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.
- lpdb_python/__init__.py +37 -0
- lpdb_python/async_session/__init__.py +3 -0
- lpdb_python/async_session/async_session.py +133 -0
- lpdb_python/defs.py +1334 -0
- lpdb_python/session.py +383 -0
- lpdb_python-0.1.0.dist-info/METADATA +85 -0
- lpdb_python-0.1.0.dist-info/RECORD +10 -0
- lpdb_python-0.1.0.dist-info/WHEEL +5 -0
- lpdb_python-0.1.0.dist-info/licenses/LICENSE +21 -0
- lpdb_python-0.1.0.dist-info/top_level.txt +1 -0
lpdb_python/__init__.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Python interface for Liquipedia Database (LPDB) API
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import importlib.metadata as _metadata
|
|
6
|
+
|
|
7
|
+
from .defs import *
|
|
8
|
+
from .session import *
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"OpponentType",
|
|
12
|
+
"Broadcasters",
|
|
13
|
+
"Company",
|
|
14
|
+
"Datapoint",
|
|
15
|
+
"ExternalMediaLink",
|
|
16
|
+
"LpdbError",
|
|
17
|
+
"LpdbWarning",
|
|
18
|
+
"LpdbSession",
|
|
19
|
+
"Match",
|
|
20
|
+
"MatchGame",
|
|
21
|
+
"MatchOpponent",
|
|
22
|
+
"Placement",
|
|
23
|
+
"Player",
|
|
24
|
+
"Series",
|
|
25
|
+
"SquadPlayer",
|
|
26
|
+
"StandingsEntry",
|
|
27
|
+
"StandingsTable",
|
|
28
|
+
"Team",
|
|
29
|
+
"Tournament",
|
|
30
|
+
"Transfer",
|
|
31
|
+
"TeamTemplate",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
__version__ = _metadata.version(__name__)
|
|
36
|
+
except _metadata.PackageNotFoundError:
|
|
37
|
+
__version__ = "0.0.0"
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from datetime import date
|
|
2
|
+
from http import HTTPStatus
|
|
3
|
+
from types import TracebackType
|
|
4
|
+
from typing import Any, Literal, Optional, override
|
|
5
|
+
|
|
6
|
+
import aiohttp
|
|
7
|
+
|
|
8
|
+
from ..session import AbstractLpdbSession, LpdbDataType, LpdbError
|
|
9
|
+
|
|
10
|
+
__all__ = ["AsyncLpdbSession"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AsyncLpdbSession(AbstractLpdbSession):
|
|
14
|
+
"""
|
|
15
|
+
Asynchronous implementation of a LPDB session
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
__session: aiohttp.ClientSession
|
|
19
|
+
|
|
20
|
+
def __init__(self, api_key, base_url=AbstractLpdbSession.BASE_URL):
|
|
21
|
+
super().__init__(api_key, base_url=base_url)
|
|
22
|
+
self.__session = aiohttp.ClientSession(
|
|
23
|
+
self._base_url, headers=self._get_header()
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def __enter__(self) -> None:
|
|
27
|
+
raise TypeError("Use async with instead")
|
|
28
|
+
|
|
29
|
+
def __exit__(
|
|
30
|
+
self,
|
|
31
|
+
exc_type: Optional[type[BaseException]],
|
|
32
|
+
exc_val: Optional[BaseException],
|
|
33
|
+
exc_tb: Optional[TracebackType],
|
|
34
|
+
) -> None:
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
async def __aenter__(self) -> "AsyncLpdbSession":
|
|
38
|
+
return self
|
|
39
|
+
|
|
40
|
+
async def __aexit__(
|
|
41
|
+
self,
|
|
42
|
+
exc_type: Optional[type[BaseException]],
|
|
43
|
+
exc_val: Optional[BaseException],
|
|
44
|
+
exc_tb: Optional[TracebackType],
|
|
45
|
+
) -> None:
|
|
46
|
+
await self.__session.close()
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
async def get_wikis() -> set[str]:
|
|
50
|
+
async with aiohttp.ClientSession("https://liquipedia.net/") as session:
|
|
51
|
+
async with session.get(
|
|
52
|
+
"api.php",
|
|
53
|
+
params={"action": "listwikis"},
|
|
54
|
+
headers={"accept": "application/json", "accept-encoding": "gzip"},
|
|
55
|
+
) as response:
|
|
56
|
+
wikis = await response.json()
|
|
57
|
+
return set(wikis["allwikis"].keys())
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
async def __handle_response(
|
|
61
|
+
response: aiohttp.ClientResponse,
|
|
62
|
+
) -> list[dict[str, Any]]:
|
|
63
|
+
return AbstractLpdbSession._parse_results(
|
|
64
|
+
response.status, await response.json()
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
@override
|
|
68
|
+
async def make_request(
|
|
69
|
+
self,
|
|
70
|
+
lpdb_datatype: LpdbDataType,
|
|
71
|
+
wiki: str | list[str],
|
|
72
|
+
limit: int = 20,
|
|
73
|
+
offset: int = 0,
|
|
74
|
+
conditions: Optional[str] = None,
|
|
75
|
+
query: Optional[str | list[str]] = None,
|
|
76
|
+
order: Optional[str | list[tuple[str, Literal["asc", "desc"]]]] = None,
|
|
77
|
+
groupby: Optional[str | list[tuple[str, Literal["asc", "desc"]]]] = None,
|
|
78
|
+
**kwargs,
|
|
79
|
+
) -> list[dict[str, Any]]:
|
|
80
|
+
if not AbstractLpdbSession._validate_datatype_name(lpdb_datatype):
|
|
81
|
+
raise ValueError(f'Invalid LPDB data type: "{lpdb_datatype}"')
|
|
82
|
+
async with self.__session.get(
|
|
83
|
+
lpdb_datatype,
|
|
84
|
+
params=AbstractLpdbSession._parse_params(
|
|
85
|
+
wiki=wiki,
|
|
86
|
+
limit=limit,
|
|
87
|
+
offset=offset,
|
|
88
|
+
conditions=conditions,
|
|
89
|
+
query=query,
|
|
90
|
+
order=order,
|
|
91
|
+
groupby=groupby,
|
|
92
|
+
**kwargs,
|
|
93
|
+
),
|
|
94
|
+
) as response:
|
|
95
|
+
return await AsyncLpdbSession.__handle_response(response)
|
|
96
|
+
|
|
97
|
+
@override
|
|
98
|
+
async def make_count_request(
|
|
99
|
+
self,
|
|
100
|
+
lpdb_datatype,
|
|
101
|
+
wiki: str,
|
|
102
|
+
conditions: Optional[str] = None,
|
|
103
|
+
) -> int:
|
|
104
|
+
response = await self.make_request(
|
|
105
|
+
lpdb_datatype, wiki=wiki, conditions=conditions, query="count::objectname"
|
|
106
|
+
)
|
|
107
|
+
return response[0]["count_objectname"]
|
|
108
|
+
|
|
109
|
+
@override
|
|
110
|
+
async def get_team_template(
|
|
111
|
+
self, wiki: str, template: str, date: Optional[date] = None
|
|
112
|
+
) -> Optional[dict[str, Any]]:
|
|
113
|
+
params = {
|
|
114
|
+
"wiki": wiki,
|
|
115
|
+
"template": template,
|
|
116
|
+
}
|
|
117
|
+
if date != None:
|
|
118
|
+
params["date"] = date.isoformat()
|
|
119
|
+
async with self.__session.get("teamtemplate", params=params) as response:
|
|
120
|
+
parsed_response = await AsyncLpdbSession.__handle_response(response)
|
|
121
|
+
if parsed_response[0] == None:
|
|
122
|
+
return None
|
|
123
|
+
return parsed_response[0]
|
|
124
|
+
|
|
125
|
+
@override
|
|
126
|
+
async def get_team_template_list(
|
|
127
|
+
self, wiki: str, pagination: int = 1
|
|
128
|
+
) -> list[dict[str, Any]]:
|
|
129
|
+
async with self.__session.get(
|
|
130
|
+
"teamtemplatelist",
|
|
131
|
+
params={"wiki": wiki, "pagination": pagination},
|
|
132
|
+
) as response:
|
|
133
|
+
return await AsyncLpdbSession.__handle_response(response)
|