ddapi 0.1.1__tar.gz → 0.1.2__tar.gz
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.
- {ddapi-0.1.1 → ddapi-0.1.2}/PKG-INFO +1 -2
- ddapi-0.1.2/ddapi/ddapi/DDnetApiPy/main.py +61 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi/qwikDDnetApiPy/main.py +15 -6
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi.egg-info/PKG-INFO +1 -2
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi.egg-info/requires.txt +0 -1
- {ddapi-0.1.1 → ddapi-0.1.2}/pyproject.toml +2 -3
- {ddapi-0.1.1 → ddapi-0.1.2}/setup.cfg +1 -1
- {ddapi-0.1.1 → ddapi-0.1.2}/setup.py +1 -1
- ddapi-0.1.1/ddapi/ddapi/DDnetApiPy/main.py +0 -48
- {ddapi-0.1.1 → ddapi-0.1.2}/LICENSE +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/README.md +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi/DDnetApiPy/__init__.py +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi/__init__.py +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi/dataclass.py +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi/errors.py +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi/misc.py +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi/qwikDDnetApiPy/__init__.py +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi.egg-info/SOURCES.txt +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi.egg-info/dependency_links.txt +0 -0
- {ddapi-0.1.1 → ddapi-0.1.2}/ddapi/ddapi.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ddapi
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: ddapi
|
|
5
5
|
Home-page: https://github.com/ByFox213/ddapi
|
|
6
6
|
Author: ByFox
|
|
@@ -36,7 +36,6 @@ Description-Content-Type: text/markdown
|
|
|
36
36
|
License-File: LICENSE
|
|
37
37
|
Requires-Dist: pydantic
|
|
38
38
|
Requires-Dist: aiohttp
|
|
39
|
-
Requires-Dist: orjson
|
|
40
39
|
Provides-Extra: dev
|
|
41
40
|
Requires-Dist: pydantic; extra == "dev"
|
|
42
41
|
Requires-Dist: aiohttp; extra == "dev"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
from aiohttp import ClientSession
|
|
3
|
+
from typing import Union
|
|
4
|
+
from json import JSONDecoder
|
|
5
|
+
from aiohttp.typedefs import DEFAULT_JSON_DECODER
|
|
6
|
+
from ..errors import ExceptConnection
|
|
7
|
+
from ..dataclass import DDPlayer
|
|
8
|
+
from ..misc import username_encode
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DDnetApi:
|
|
12
|
+
def __init__(self,
|
|
13
|
+
session: ClientSession = None,
|
|
14
|
+
on_raise: bool = True,
|
|
15
|
+
json_loads: JSONDecoder = DEFAULT_JSON_DECODER):
|
|
16
|
+
self.session = session
|
|
17
|
+
self.on_raise = on_raise
|
|
18
|
+
self.json_loads = json_loads
|
|
19
|
+
self.url = "https://ddstats.qwik.space/player/json?player={0}"
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def closed(self):
|
|
23
|
+
return self.session.closed is None or self.session.closed
|
|
24
|
+
|
|
25
|
+
async def _ch_start(self) -> None:
|
|
26
|
+
if self.session is None:
|
|
27
|
+
self.session = aiohttp.ClientSession()
|
|
28
|
+
|
|
29
|
+
async def _send(self, url: str) -> Union[dict, None]:
|
|
30
|
+
await self._ch_start()
|
|
31
|
+
try:
|
|
32
|
+
async with self.session.get(url) as req:
|
|
33
|
+
if req.status == 200:
|
|
34
|
+
usr = await req.text()
|
|
35
|
+
if usr == '{}' or usr is None:
|
|
36
|
+
return
|
|
37
|
+
del usr
|
|
38
|
+
return await req.json(loads=self.json_loads)
|
|
39
|
+
return
|
|
40
|
+
except Exception as ex:
|
|
41
|
+
if self.on_raise:
|
|
42
|
+
raise ExceptConnection(f"This hosting may not be available at the moment: {ex}")
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
async def close(self) -> None:
|
|
46
|
+
return await self.session.close()
|
|
47
|
+
|
|
48
|
+
async def player(self, player: str) -> Union[DDPlayer, None]:
|
|
49
|
+
dat = await self._send(f"https://ddnet.org/players/?json2={username_encode(player)}")
|
|
50
|
+
if dat is None:
|
|
51
|
+
return
|
|
52
|
+
return DDPlayer(**dat)
|
|
53
|
+
|
|
54
|
+
async def dict_player(self, player: str) -> Union[dict, None]:
|
|
55
|
+
dat = await self._send(f"https://ddnet.org/players/?json2={username_encode(player)}")
|
|
56
|
+
if dat is None:
|
|
57
|
+
return
|
|
58
|
+
return dat
|
|
59
|
+
|
|
60
|
+
async def master(self) -> Union[dict, None]:
|
|
61
|
+
return await self._send("https://master1.ddnet.org/ddnet/15/servers.json")
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import aiohttp
|
|
2
|
-
import orjson
|
|
3
2
|
from aiohttp import ClientSession
|
|
3
|
+
from typing import Union
|
|
4
|
+
from json import JSONDecoder
|
|
5
|
+
from aiohttp.typedefs import DEFAULT_JSON_DECODER
|
|
4
6
|
from ..dataclass import Player
|
|
5
7
|
from ..misc import username_encode
|
|
6
8
|
from ..errors import ExceptConnection
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
class QwikAPI:
|
|
10
|
-
def __init__(self,
|
|
12
|
+
def __init__(self,
|
|
13
|
+
session: ClientSession = None,
|
|
14
|
+
on_raise: bool = True,
|
|
15
|
+
json_loads: JSONDecoder = DEFAULT_JSON_DECODER):
|
|
11
16
|
self.session = session
|
|
17
|
+
self.on_raise = on_raise
|
|
18
|
+
self.json_loads = json_loads
|
|
12
19
|
self.url = "https://ddstats.qwik.space/player/json?player={0}"
|
|
13
20
|
|
|
14
21
|
@property
|
|
@@ -19,7 +26,7 @@ class QwikAPI:
|
|
|
19
26
|
if self.session is None:
|
|
20
27
|
self.session = aiohttp.ClientSession()
|
|
21
28
|
|
|
22
|
-
async def _send(self, player: str) -> dict
|
|
29
|
+
async def _send(self, player: str) -> Union[dict, None]:
|
|
23
30
|
await self._ch_start()
|
|
24
31
|
try:
|
|
25
32
|
async with self.session.get(self.url.format(username_encode(player))) as req:
|
|
@@ -28,12 +35,14 @@ class QwikAPI:
|
|
|
28
35
|
if usr == '{}' or usr is None:
|
|
29
36
|
return
|
|
30
37
|
del usr
|
|
31
|
-
return await req.json(loads=
|
|
38
|
+
return await req.json(loads=self.json_loads)
|
|
32
39
|
return
|
|
33
40
|
except Exception as ex:
|
|
34
|
-
|
|
41
|
+
if self.on_raise:
|
|
42
|
+
raise ExceptConnection(f"This hosting may not be available at the moment: {ex}")
|
|
43
|
+
return
|
|
35
44
|
|
|
36
|
-
async def player(self, nickname) -> Player
|
|
45
|
+
async def player(self, nickname) -> Union[Player, None]:
|
|
37
46
|
dat = await self._send(nickname)
|
|
38
47
|
if not dat:
|
|
39
48
|
return
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ddapi
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: ddapi
|
|
5
5
|
Home-page: https://github.com/ByFox213/ddapi
|
|
6
6
|
Author: ByFox
|
|
@@ -36,7 +36,6 @@ Description-Content-Type: text/markdown
|
|
|
36
36
|
License-File: LICENSE
|
|
37
37
|
Requires-Dist: pydantic
|
|
38
38
|
Requires-Dist: aiohttp
|
|
39
|
-
Requires-Dist: orjson
|
|
40
39
|
Provides-Extra: dev
|
|
41
40
|
Requires-Dist: pydantic; extra == "dev"
|
|
42
41
|
Requires-Dist: aiohttp; extra == "dev"
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ddapi"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "ddapi"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "ByFox" }]
|
|
@@ -17,8 +17,7 @@ classifiers = [
|
|
|
17
17
|
keywords = ["feed", "reader", "tutorial"]
|
|
18
18
|
dependencies = [
|
|
19
19
|
"pydantic",
|
|
20
|
-
"aiohttp"
|
|
21
|
-
'orjson'
|
|
20
|
+
"aiohttp"
|
|
22
21
|
]
|
|
23
22
|
requires-python = ">=3.8"
|
|
24
23
|
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import aiohttp
|
|
2
|
-
import orjson
|
|
3
|
-
from aiohttp import ClientSession
|
|
4
|
-
from ..dataclass import DDPlayer
|
|
5
|
-
from ..misc import username_encode
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class DDnetApi:
|
|
9
|
-
def __init__(self, session: ClientSession = None):
|
|
10
|
-
self.session = session
|
|
11
|
-
self.url = "https://ddstats.qwik.space/player/json?player={0}"
|
|
12
|
-
|
|
13
|
-
@property
|
|
14
|
-
def closed(self):
|
|
15
|
-
return self.session.closed is None or self.session.closed
|
|
16
|
-
|
|
17
|
-
async def _ch_start(self) -> None:
|
|
18
|
-
if self.session is None:
|
|
19
|
-
self.session = aiohttp.ClientSession()
|
|
20
|
-
|
|
21
|
-
async def _send(self, url: str) -> dict | None:
|
|
22
|
-
await self._ch_start()
|
|
23
|
-
async with self.session.get(url) as req:
|
|
24
|
-
if req.status == 200:
|
|
25
|
-
usr = await req.text()
|
|
26
|
-
if usr == '{}' or usr is None:
|
|
27
|
-
return
|
|
28
|
-
del usr
|
|
29
|
-
return await req.json(loads=orjson.loads)
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
async def close(self) -> None:
|
|
33
|
-
return await self.session.close()
|
|
34
|
-
|
|
35
|
-
async def player(self, player: str) -> DDPlayer | None:
|
|
36
|
-
dat = await self._send(f"https://ddnet.org/players/?json2={username_encode(player)}")
|
|
37
|
-
if dat is None:
|
|
38
|
-
return
|
|
39
|
-
return DDPlayer(**dat)
|
|
40
|
-
|
|
41
|
-
async def dict_player(self, player: str) -> dict | None:
|
|
42
|
-
dat = await self._send(f"https://ddnet.org/players/?json2={username_encode(player)}")
|
|
43
|
-
if dat is None:
|
|
44
|
-
return
|
|
45
|
-
return dat
|
|
46
|
-
|
|
47
|
-
async def master(self) -> dict | None:
|
|
48
|
-
return await self._send("https://master1.ddnet.org/ddnet/15/servers.json")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|