ddapi 0.1.0__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.0/LICENSE ADDED
@@ -0,0 +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.
ddapi-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.1
2
+ Name: ddapi
3
+ Version: 0.1.0
4
+ Summary: ddapi
5
+ Home-page: https://github.com/ByFox213/ddapi
6
+ Author: ByFox
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 ByFox
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/ByFox213/ddapi
30
+ Keywords: feed,reader,tutorial
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python
33
+ Classifier: Programming Language :: Python :: 3
34
+ Requires-Python: >=3.8
35
+ Description-Content-Type: text/markdown
36
+ License-File: LICENSE
37
+ Requires-Dist: pydantic
38
+ Requires-Dist: aiohttp
39
+ Requires-Dist: orjson
40
+ Provides-Extra: dev
41
+ Requires-Dist: pydantic; extra == "dev"
42
+ Requires-Dist: aiohttp; extra == "dev"
43
+ Requires-Dist: orjson; extra == "dev"
44
+ Requires-Dist: pip-tools; extra == "dev"
45
+ Requires-Dist: pytest; extra == "dev"
46
+
47
+ ddapi is an api from the ddnet and qwik website
48
+ ## Installation
49
+
50
+ ```bash
51
+ pip install ddapi
52
+ ```
53
+
54
+ ## Usage/Examples
55
+
56
+ DDnet
57
+ ```python
58
+ import asyncio
59
+ from ddapi import DDnetApi, DDPlayer
60
+
61
+
62
+ async def main():
63
+ obj = DDnetApi()
64
+ nickname = "Cor"
65
+ user: DDPlayer = await obj.player(nickname)
66
+ if user is None:
67
+ return "Player not found"
68
+ print(f"{user.player}: {user.points.points}")
69
+ # Cor: 31473
70
+ await obj.close() # Closing client Not necessary
71
+ assert isinstance(user, DDPlayer)
72
+
73
+
74
+ asyncio.run(main())
75
+ ```
76
+
77
+ qwik
78
+
79
+ ```python
80
+ import asyncio
81
+ from ddapi import Player, QwikAPI
82
+
83
+
84
+ async def main():
85
+ obj = QwikAPI()
86
+ nickname = "ByFox"
87
+ user = await obj.player(nickname)
88
+ if user is None:
89
+ return "Player not found"
90
+ print(f"{user.player}: {user.points.points}")
91
+ # Cor: 31473
92
+ await obj.close() # Closing client Not necessary
93
+ assert isinstance(user, Player)
94
+
95
+
96
+ asyncio.run(main())
97
+ ```
ddapi-0.1.0/README.md ADDED
@@ -0,0 +1,51 @@
1
+ ddapi is an api from the ddnet and qwik website
2
+ ## Installation
3
+
4
+ ```bash
5
+ pip install ddapi
6
+ ```
7
+
8
+ ## Usage/Examples
9
+
10
+ DDnet
11
+ ```python
12
+ import asyncio
13
+ from ddapi import DDnetApi, DDPlayer
14
+
15
+
16
+ async def main():
17
+ obj = DDnetApi()
18
+ nickname = "Cor"
19
+ user: DDPlayer = await obj.player(nickname)
20
+ if user is None:
21
+ return "Player not found"
22
+ print(f"{user.player}: {user.points.points}")
23
+ # Cor: 31473
24
+ await obj.close() # Closing client Not necessary
25
+ assert isinstance(user, DDPlayer)
26
+
27
+
28
+ asyncio.run(main())
29
+ ```
30
+
31
+ qwik
32
+
33
+ ```python
34
+ import asyncio
35
+ from ddapi import Player, QwikAPI
36
+
37
+
38
+ async def main():
39
+ obj = QwikAPI()
40
+ nickname = "ByFox"
41
+ user = await obj.player(nickname)
42
+ if user is None:
43
+ return "Player not found"
44
+ print(f"{user.player}: {user.points.points}")
45
+ # Cor: 31473
46
+ await obj.close() # Closing client Not necessary
47
+ assert isinstance(user, Player)
48
+
49
+
50
+ asyncio.run(main())
51
+ ```
@@ -0,0 +1 @@
1
+ from .main import DDnetApi
@@ -0,0 +1,48 @@
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")
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.1
2
+ Name: ddapi
3
+ Version: 0.1.0
4
+ Summary: ddapi
5
+ Home-page: https://github.com/ByFox213/ddapi
6
+ Author: ByFox
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 ByFox
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/ByFox213/ddapi
30
+ Keywords: feed,reader,tutorial
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python
33
+ Classifier: Programming Language :: Python :: 3
34
+ Requires-Python: >=3.8
35
+ Description-Content-Type: text/markdown
36
+ License-File: LICENSE
37
+ Requires-Dist: pydantic
38
+ Requires-Dist: aiohttp
39
+ Requires-Dist: orjson
40
+ Provides-Extra: dev
41
+ Requires-Dist: pydantic; extra == "dev"
42
+ Requires-Dist: aiohttp; extra == "dev"
43
+ Requires-Dist: orjson; extra == "dev"
44
+ Requires-Dist: pip-tools; extra == "dev"
45
+ Requires-Dist: pytest; extra == "dev"
46
+
47
+ ddapi is an api from the ddnet and qwik website
48
+ ## Installation
49
+
50
+ ```bash
51
+ pip install ddapi
52
+ ```
53
+
54
+ ## Usage/Examples
55
+
56
+ DDnet
57
+ ```python
58
+ import asyncio
59
+ from ddapi import DDnetApi, DDPlayer
60
+
61
+
62
+ async def main():
63
+ obj = DDnetApi()
64
+ nickname = "Cor"
65
+ user: DDPlayer = await obj.player(nickname)
66
+ if user is None:
67
+ return "Player not found"
68
+ print(f"{user.player}: {user.points.points}")
69
+ # Cor: 31473
70
+ await obj.close() # Closing client Not necessary
71
+ assert isinstance(user, DDPlayer)
72
+
73
+
74
+ asyncio.run(main())
75
+ ```
76
+
77
+ qwik
78
+
79
+ ```python
80
+ import asyncio
81
+ from ddapi import Player, QwikAPI
82
+
83
+
84
+ async def main():
85
+ obj = QwikAPI()
86
+ nickname = "ByFox"
87
+ user = await obj.player(nickname)
88
+ if user is None:
89
+ return "Player not found"
90
+ print(f"{user.player}: {user.points.points}")
91
+ # Cor: 31473
92
+ await obj.close() # Closing client Not necessary
93
+ assert isinstance(user, Player)
94
+
95
+
96
+ asyncio.run(main())
97
+ ```
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ setup.py
6
+ ddapi/DDnetApiPy/__init__.py
7
+ ddapi/DDnetApiPy/main.py
8
+ ddapi/ddapi.egg-info/PKG-INFO
9
+ ddapi/ddapi.egg-info/SOURCES.txt
10
+ ddapi/ddapi.egg-info/dependency_links.txt
11
+ ddapi/ddapi.egg-info/requires.txt
12
+ ddapi/ddapi.egg-info/top_level.txt
13
+ ddapi/qwikDDnetApiPy/__init__.py
14
+ ddapi/qwikDDnetApiPy/main.py
@@ -0,0 +1,10 @@
1
+ pydantic
2
+ aiohttp
3
+ orjson
4
+
5
+ [dev]
6
+ pydantic
7
+ aiohttp
8
+ orjson
9
+ pip-tools
10
+ pytest
@@ -0,0 +1,2 @@
1
+ DDnetApiPy
2
+ qwikDDnetApiPy
@@ -0,0 +1 @@
1
+ from .main import QwikAPI
@@ -0,0 +1,43 @@
1
+ import aiohttp
2
+ import orjson
3
+ from aiohttp import ClientSession
4
+ from ..dataclass import Player
5
+ from ..misc import username_encode
6
+ from ..errors import ExceptConnection
7
+
8
+
9
+ class QwikAPI:
10
+ def __init__(self, session: ClientSession = None):
11
+ self.session = session
12
+ self.url = "https://ddstats.qwik.space/player/json?player={0}"
13
+
14
+ @property
15
+ def closed(self):
16
+ return self.session.closed is None or self.session.closed
17
+
18
+ async def _ch_start(self) -> None:
19
+ if self.session is None:
20
+ self.session = aiohttp.ClientSession()
21
+
22
+ async def _send(self, player: str) -> dict | None:
23
+ await self._ch_start()
24
+ try:
25
+ async with self.session.get(self.url.format(username_encode(player))) as req:
26
+ if req.status == 200:
27
+ usr = await req.text()
28
+ if usr == '{}' or usr is None:
29
+ return
30
+ del usr
31
+ return await req.json(loads=orjson.loads)
32
+ return
33
+ except Exception as ex:
34
+ raise ExceptConnection(f"This hosting may not be available at the moment: {ex}")
35
+
36
+ async def player(self, nickname) -> Player | None:
37
+ dat = await self._send(nickname)
38
+ if not dat:
39
+ return
40
+ return Player(**dat)
41
+
42
+ async def close(self) -> None:
43
+ await self.session.close()
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ddapi"
7
+ version = "0.1.0"
8
+ description = "ddapi"
9
+ readme = "README.md"
10
+ authors = [{ name = "ByFox" }]
11
+ license = { file = "LICENSE" }
12
+ classifiers = [
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python",
15
+ "Programming Language :: Python :: 3",
16
+ ]
17
+ keywords = ["feed", "reader", "tutorial"]
18
+ dependencies = [
19
+ "pydantic",
20
+ "aiohttp",
21
+ 'orjson'
22
+ ]
23
+ requires-python = ">=3.8"
24
+
25
+ [project.optional-dependencies]
26
+ dev = ["pydantic", "aiohttp", "orjson", "pip-tools", "pytest"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/ByFox213/ddapi"
ddapi-0.1.0/setup.cfg ADDED
@@ -0,0 +1,28 @@
1
+ [metadata]
2
+ name = ddapi
3
+ version = 0.10
4
+ author = ByFox
5
+ description = DDnet api
6
+ long_description = file: README.md
7
+ long_description_content_type = text/markdown
8
+ url = https://github.com/ByFox213/ddapi
9
+ project_urls =
10
+ github = https://github.com/ByFox213/ddapi
11
+ classifiers =
12
+ Programming Language :: Python :: 3
13
+ License :: OSI Approved :: MIT License
14
+ Operating System :: OS Independent
15
+
16
+ [options]
17
+ package_dir =
18
+ = ddapi
19
+ packages = find:
20
+ python_requires = >=3.8
21
+
22
+ [options.packages.find]
23
+ where = ddapi
24
+
25
+ [egg_info]
26
+ tag_build =
27
+ tag_date = 0
28
+
ddapi-0.1.0/setup.py ADDED
@@ -0,0 +1,25 @@
1
+ import setuptools
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setuptools.setup(
7
+ name="ddapi-py",
8
+ version="0.10",
9
+ author="ByFox",
10
+ description="DDnet api",
11
+ long_description=long_description,
12
+ long_description_content_type="text/markdown",
13
+ url="https://github.com/ByFox213/ddapi",
14
+ project_urls={
15
+ "Github": "https://github.com/ByFox213/ddapi"
16
+ },
17
+ classifiers=[
18
+ "Programming Language :: Python :: 3",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ ],
22
+ package_dir={"": "ddapi"},
23
+ packages=setuptools.find_packages(where="src"),
24
+ python_requires=">=3.8"
25
+ )