ddapi 0.12.2__tar.gz → 0.13.1__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.12.2 → ddapi-0.13.1}/LICENSE +21 -21
- {ddapi-0.12.2 → ddapi-0.13.1}/PKG-INFO +66 -66
- {ddapi-0.12.2 → ddapi-0.13.1}/README.md +45 -45
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi/__init__.py +10 -8
- ddapi-0.12.2/ddapi/ddapi/api.py → ddapi-0.13.1/ddapi/ddapi/_api.py +115 -90
- ddapi-0.13.1/ddapi/ddapi/api/__init__.py +3 -0
- ddapi-0.13.1/ddapi/ddapi/api/ddnet.py +72 -0
- ddapi-0.13.1/ddapi/ddapi/api/ddstats.py +44 -0
- ddapi-0.12.2/ddapi/ddapi/main.py → ddapi-0.13.1/ddapi/ddapi/api/status.py +134 -242
- ddapi-0.13.1/ddapi/ddapi/cache/__init__.py +3 -0
- ddapi-0.13.1/ddapi/ddapi/cache/base.py +32 -0
- ddapi-0.13.1/ddapi/ddapi/cache/empty.py +14 -0
- ddapi-0.13.1/ddapi/ddapi/cache/memory.py +28 -0
- ddapi-0.13.1/ddapi/ddapi/enum.py +10 -0
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi/scheme/__init__.py +3 -3
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi/scheme/ddnet.py +328 -328
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi/scheme/ddstats_tw.py +280 -280
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi/scheme/status_tw.py +131 -131
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi/types.py +3 -3
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi.egg-info/PKG-INFO +66 -66
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi.egg-info/SOURCES.txt +10 -2
- {ddapi-0.12.2 → ddapi-0.13.1}/setup.cfg +25 -25
- {ddapi-0.12.2 → ddapi-0.13.1}/setup.py +19 -19
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi.egg-info/dependency_links.txt +0 -0
- {ddapi-0.12.2 → ddapi-0.13.1}/ddapi/ddapi.egg-info/top_level.txt +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 ByFox
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ByFox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ddapi
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: DDnet api
|
|
5
|
-
Home-page: https://github.com/ByFox213/ddapi
|
|
6
|
-
Author: ByFox
|
|
7
|
-
License: MIT
|
|
8
|
-
Project-URL: Github, https://github.com/ByFox213/ddapi
|
|
9
|
-
Requires-Python: >=3.10
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
Dynamic: author
|
|
13
|
-
Dynamic: description
|
|
14
|
-
Dynamic: description-content-type
|
|
15
|
-
Dynamic: home-page
|
|
16
|
-
Dynamic: license
|
|
17
|
-
Dynamic: license-file
|
|
18
|
-
Dynamic: project-url
|
|
19
|
-
Dynamic: requires-python
|
|
20
|
-
Dynamic: summary
|
|
21
|
-
|
|
22
|
-
ddapi is an api from the ddnet and qwik website
|
|
23
|
-
|
|
24
|
-
## Installation
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
pip install ddapi
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
or
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
pip install git+https://github.com/ByFox213/ddapi
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Usage/Examples
|
|
37
|
-
|
|
38
|
-
DDnet
|
|
39
|
-
|
|
40
|
-
```python
|
|
41
|
-
import asyncio
|
|
42
|
-
|
|
43
|
-
from ddapi import DDnetApi, DDPlayer
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
async def main():
|
|
47
|
-
async with DDnetApi() as obj:
|
|
48
|
-
user: DDPlayer = await obj.player("Cor")
|
|
49
|
-
if user is not None:
|
|
50
|
-
text = f"{user.player}: {user.points.points}/{user.points.total}"
|
|
51
|
-
percent = round(user.points.total / user.points.points * 100)
|
|
52
|
-
print(f"{text}({percent}%)")
|
|
53
|
-
# Cor: 32950/32950(100%)
|
|
54
|
-
else:
|
|
55
|
-
print("Player not found")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
asyncio.run(main())
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Tested on Python
|
|
62
|
-
| 3.
|
|
63
|
-
|------|------|------|
|
|
64
|
-
| ✅ | ✅ | ✅ |
|
|
65
|
-
|
|
66
|
-
[other examples](https://github.com/ByFox213/ddapi/tree/main/example)
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ddapi
|
|
3
|
+
Version: 0.13.1
|
|
4
|
+
Summary: DDnet api
|
|
5
|
+
Home-page: https://github.com/ByFox213/ddapi
|
|
6
|
+
Author: ByFox
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Github, https://github.com/ByFox213/ddapi
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: description
|
|
14
|
+
Dynamic: description-content-type
|
|
15
|
+
Dynamic: home-page
|
|
16
|
+
Dynamic: license
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: project-url
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
ddapi is an api from the ddnet and qwik website
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install ddapi
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install git+https://github.com/ByFox213/ddapi
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage/Examples
|
|
37
|
+
|
|
38
|
+
DDnet
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import asyncio
|
|
42
|
+
|
|
43
|
+
from ddapi import DDnetApi, DDPlayer
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def main():
|
|
47
|
+
async with DDnetApi() as obj:
|
|
48
|
+
user: DDPlayer = await obj.player("Cor")
|
|
49
|
+
if user is not None:
|
|
50
|
+
text = f"{user.player}: {user.points.points}/{user.points.total}"
|
|
51
|
+
percent = round(user.points.total / user.points.points * 100)
|
|
52
|
+
print(f"{text}({percent}%)")
|
|
53
|
+
# Cor: 32950/32950(100%)
|
|
54
|
+
else:
|
|
55
|
+
print("Player not found")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
asyncio.run(main())
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Tested on Python
|
|
62
|
+
| 3.11 | 3.12 | 3.13 |
|
|
63
|
+
|------|------|------|
|
|
64
|
+
| ✅ | ✅ | ✅ |
|
|
65
|
+
|
|
66
|
+
[other examples](https://github.com/ByFox213/ddapi/tree/main/example)
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
ddapi is an api from the ddnet and qwik website
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
pip install ddapi
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
or
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pip install git+https://github.com/ByFox213/ddapi
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage/Examples
|
|
16
|
-
|
|
17
|
-
DDnet
|
|
18
|
-
|
|
19
|
-
```python
|
|
20
|
-
import asyncio
|
|
21
|
-
|
|
22
|
-
from ddapi import DDnetApi, DDPlayer
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
async def main():
|
|
26
|
-
async with DDnetApi() as obj:
|
|
27
|
-
user: DDPlayer = await obj.player("Cor")
|
|
28
|
-
if user is not None:
|
|
29
|
-
text = f"{user.player}: {user.points.points}/{user.points.total}"
|
|
30
|
-
percent = round(user.points.total / user.points.points * 100)
|
|
31
|
-
print(f"{text}({percent}%)")
|
|
32
|
-
# Cor: 32950/32950(100%)
|
|
33
|
-
else:
|
|
34
|
-
print("Player not found")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
asyncio.run(main())
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Tested on Python
|
|
41
|
-
| 3.
|
|
42
|
-
|------|------|------|
|
|
43
|
-
| ✅ | ✅ | ✅ |
|
|
44
|
-
|
|
45
|
-
[other examples](https://github.com/ByFox213/ddapi/tree/main/example)
|
|
1
|
+
ddapi is an api from the ddnet and qwik website
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install ddapi
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install git+https://github.com/ByFox213/ddapi
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage/Examples
|
|
16
|
+
|
|
17
|
+
DDnet
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import asyncio
|
|
21
|
+
|
|
22
|
+
from ddapi import DDnetApi, DDPlayer
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async def main():
|
|
26
|
+
async with DDnetApi() as obj:
|
|
27
|
+
user: DDPlayer = await obj.player("Cor")
|
|
28
|
+
if user is not None:
|
|
29
|
+
text = f"{user.player}: {user.points.points}/{user.points.total}"
|
|
30
|
+
percent = round(user.points.total / user.points.points * 100)
|
|
31
|
+
print(f"{text}({percent}%)")
|
|
32
|
+
# Cor: 32950/32950(100%)
|
|
33
|
+
else:
|
|
34
|
+
print("Player not found")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
asyncio.run(main())
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Tested on Python
|
|
41
|
+
| 3.11 | 3.12 | 3.13 |
|
|
42
|
+
|------|------|------|
|
|
43
|
+
| ✅ | ✅ | ✅ |
|
|
44
|
+
|
|
45
|
+
[other examples](https://github.com/ByFox213/ddapi/tree/main/example)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
"""the module is made for the convenience of users to download and use"""
|
|
2
|
-
|
|
3
|
-
from .
|
|
4
|
-
from .
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"""the module is made for the convenience of users to download and use"""
|
|
2
|
+
|
|
3
|
+
from .api import DDnetApi, DDstats, Status
|
|
4
|
+
from .enum import MasterEnum
|
|
5
|
+
from .cache import CacheABC, EmptyCache, MemoryCache
|
|
6
|
+
from .scheme import * # noqa: F403
|
|
7
|
+
|
|
8
|
+
__version__ = "0.13.1"
|
|
9
|
+
__author__ = "ByFox"
|
|
10
|
+
__LICENSE__ = "MIT"
|
|
@@ -1,90 +1,115 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
self
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
async def
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async def
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
1
|
+
import asyncio
|
|
2
|
+
import atexit
|
|
3
|
+
import logging
|
|
4
|
+
from abc import ABC
|
|
5
|
+
from typing import Optional, Type, Any
|
|
6
|
+
|
|
7
|
+
import aiohttp
|
|
8
|
+
from aiohttp import ClientSession
|
|
9
|
+
|
|
10
|
+
from ddapi.cache import CacheABC, EmptyCache
|
|
11
|
+
from ddapi.types import T
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
import orjson
|
|
15
|
+
|
|
16
|
+
DEFAULT_JSON_DECODER = orjson.loads
|
|
17
|
+
except ImportError:
|
|
18
|
+
from aiohttp.typedefs import DEFAULT_JSON_DECODER
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class API(ABC):
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
session: ClientSession = None,
|
|
27
|
+
*,
|
|
28
|
+
autoclose: bool = True,
|
|
29
|
+
cache: CacheABC = EmptyCache(),
|
|
30
|
+
json_loads: Any = DEFAULT_JSON_DECODER,
|
|
31
|
+
):
|
|
32
|
+
self.__session = session
|
|
33
|
+
self.cache = cache
|
|
34
|
+
self.json_loads = json_loads
|
|
35
|
+
self.autoclose = autoclose
|
|
36
|
+
|
|
37
|
+
if self.__session is None:
|
|
38
|
+
self.__session = aiohttp.ClientSession()
|
|
39
|
+
logger.debug("Created a new aiohttp ClientSession.")
|
|
40
|
+
|
|
41
|
+
atexit.register(self.close_api)
|
|
42
|
+
|
|
43
|
+
async def __aenter__(self):
|
|
44
|
+
if self.__session is None:
|
|
45
|
+
self.__session = aiohttp.ClientSession()
|
|
46
|
+
logger.debug("Created a new aiohttp ClientSession on enter.")
|
|
47
|
+
return self
|
|
48
|
+
|
|
49
|
+
async def __aexit__(self, _exc_type, _exc_val, _exc_tb):
|
|
50
|
+
if self.autoclose:
|
|
51
|
+
logger.debug("Closing aiohttp ClientSession on exit.")
|
|
52
|
+
await self.close()
|
|
53
|
+
|
|
54
|
+
async def _get(self, url: str) -> Optional[dict]:
|
|
55
|
+
"""Send a GET request to the given URL and return the response as JSON."""
|
|
56
|
+
logger.debug(f"Sending GET request to {url}.")
|
|
57
|
+
async with self.__session.get(url) as req:
|
|
58
|
+
if req.status == 200:
|
|
59
|
+
logger.debug(f"Received response from {url}: {req.status}.")
|
|
60
|
+
return await req.json(loads=self.json_loads)
|
|
61
|
+
logger.error(f"Failed to get response from {url}: {req.status}.")
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
async def _generate_model_instance(
|
|
65
|
+
self,
|
|
66
|
+
url: str,
|
|
67
|
+
model: Type[T],
|
|
68
|
+
k: Optional[str] = None,
|
|
69
|
+
cache_timeout: int = 300,
|
|
70
|
+
) -> Optional[T]:
|
|
71
|
+
"""Generate a model instance from the given URL and optional keyword arguments.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
url (str): The URL to fetch data from.
|
|
75
|
+
model (Type[ModelType]): The model class to instantiate.
|
|
76
|
+
k (str, optional): An optional keyword to wrap the data in a dictionary.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Optional[ModelType]: A model instance.
|
|
80
|
+
"""
|
|
81
|
+
cache = await self.cache.get(url)
|
|
82
|
+
if cache is not None:
|
|
83
|
+
return cache
|
|
84
|
+
|
|
85
|
+
dat = await self._get(url)
|
|
86
|
+
if dat is None or not dat:
|
|
87
|
+
logger.warning(f"No data received from {url}.")
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
data = model(**{k: dat} if k is not None else dat)
|
|
91
|
+
await self.cache.set(url, data, cache_timeout)
|
|
92
|
+
return data
|
|
93
|
+
|
|
94
|
+
async def is_closed(self) -> bool:
|
|
95
|
+
"""True is closed, False otherwise."""
|
|
96
|
+
return self.__session is None or self.__session.closed
|
|
97
|
+
|
|
98
|
+
async def close(self) -> None:
|
|
99
|
+
"""Close the aiohttp session."""
|
|
100
|
+
if self.__session is not None:
|
|
101
|
+
logger.debug("Closing aiohttp ClientSession.")
|
|
102
|
+
await self.__session.close()
|
|
103
|
+
self.__session = None
|
|
104
|
+
self.cache = None
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def domain(self) -> str:
|
|
108
|
+
return ""
|
|
109
|
+
|
|
110
|
+
@staticmethod
|
|
111
|
+
def powered() -> None:
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
def close_api(self):
|
|
115
|
+
asyncio.run(self.close())
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from urllib.parse import quote
|
|
2
|
+
|
|
3
|
+
from .._api import API
|
|
4
|
+
from ..scheme import (
|
|
5
|
+
DDPlayer,
|
|
6
|
+
DDStatus,
|
|
7
|
+
ReleasesMaps,
|
|
8
|
+
Query,
|
|
9
|
+
QueryMap,
|
|
10
|
+
QueryMapper,
|
|
11
|
+
Master,
|
|
12
|
+
DMap,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = ("DDnetApi",)
|
|
16
|
+
|
|
17
|
+
from ..enum import MasterEnum
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DDnetApi(API):
|
|
21
|
+
@property
|
|
22
|
+
def domain(self) -> str:
|
|
23
|
+
return "ddnet.org"
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def powered() -> str:
|
|
27
|
+
return DDnetApi().domain
|
|
28
|
+
|
|
29
|
+
async def player(self, player: str) -> DDPlayer:
|
|
30
|
+
"""Fetch player data from the API and return it as a dictionary."""
|
|
31
|
+
return await self._generate_model_instance(
|
|
32
|
+
f"https://{self.domain}/players/?json2={quote(player)}", DDPlayer
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
async def status(self) -> DDStatus:
|
|
36
|
+
return await self._generate_model_instance(
|
|
37
|
+
f"https://{self.domain}/status/json/stats.json", DDStatus
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
async def releases_map(self) -> ReleasesMaps:
|
|
41
|
+
return await self._generate_model_instance(
|
|
42
|
+
f"https://{self.domain}/releases/maps.json", ReleasesMaps, "maps"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
async def query(self, player: str) -> Query:
|
|
46
|
+
return await self._generate_model_instance(
|
|
47
|
+
f"https://{self.domain}/players/?query={quote(player)}", Query, "players"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
async def query_map(self, map_name: str) -> QueryMap:
|
|
51
|
+
return await self._generate_model_instance(
|
|
52
|
+
f"https://{self.domain}/maps/?query={quote(map_name)}",
|
|
53
|
+
QueryMap,
|
|
54
|
+
"maps",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
async def query_mapper(self, player: str) -> QueryMapper:
|
|
58
|
+
return await self._generate_model_instance(
|
|
59
|
+
f"https://{self.domain}/maps/?qmapper={quote(player)}",
|
|
60
|
+
QueryMapper,
|
|
61
|
+
"players",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
async def master(self, number: MasterEnum = MasterEnum.master1) -> Master:
|
|
65
|
+
return await self._generate_model_instance(
|
|
66
|
+
f"https://master{number}.{self.domain}/ddnet/15/servers.json", Master
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
async def map(self, map_name: str) -> DMap:
|
|
70
|
+
return await self._generate_model_instance(
|
|
71
|
+
f"https://{self.domain}/maps/?json={quote(map_name)}", DMap
|
|
72
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from urllib.parse import quote
|
|
2
|
+
|
|
3
|
+
from .._api import API
|
|
4
|
+
from ..scheme import (
|
|
5
|
+
DProfile,
|
|
6
|
+
SMap,
|
|
7
|
+
Maps,
|
|
8
|
+
Player,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = ("DDstats",)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DDstats(API):
|
|
15
|
+
@property
|
|
16
|
+
def domain(self) -> str:
|
|
17
|
+
return "ddstats.tw"
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def powered() -> str:
|
|
21
|
+
return DDstats().domain
|
|
22
|
+
|
|
23
|
+
async def profile(self, player_name: str) -> DProfile:
|
|
24
|
+
return await self._generate_model_instance(
|
|
25
|
+
f"https://{self.domain}/profile/json?player={quote(player_name)}",
|
|
26
|
+
DProfile,
|
|
27
|
+
"profile",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
async def map(self, map_name: str) -> SMap:
|
|
31
|
+
return await self._generate_model_instance(
|
|
32
|
+
f"https://{self.domain}/map/json?map={quote(map_name)}", SMap
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
async def maps(self) -> Maps:
|
|
36
|
+
return await self._generate_model_instance(
|
|
37
|
+
f"https://{self.domain}/maps/json", Maps, "maps"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
async def player(self, player_name: str) -> Player:
|
|
41
|
+
"""Fetch player data from the API and return it as a dictionary."""
|
|
42
|
+
return await self._generate_model_instance(
|
|
43
|
+
f"https://{self.domain}/player/json?player={quote(player_name)}", Player
|
|
44
|
+
)
|