simple-rule34 1.0.0.0__py3-none-any.whl → 1.0.0.2__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.
- SimpleRule34/main.py +14 -4
- SimpleRule34/types.py +10 -2
- {simple_rule34-1.0.0.0.dist-info → simple_rule34-1.0.0.2.dist-info}/METADATA +1 -1
- simple_rule34-1.0.0.2.dist-info/RECORD +11 -0
- {simple_rule34-1.0.0.0.dist-info → simple_rule34-1.0.0.2.dist-info}/WHEEL +1 -1
- simple_rule34-1.0.0.0.dist-info/RECORD +0 -11
- {simple_rule34-1.0.0.0.dist-info → simple_rule34-1.0.0.2.dist-info}/licenses/LICENSE +0 -0
- {simple_rule34-1.0.0.0.dist-info → simple_rule34-1.0.0.2.dist-info}/top_level.txt +0 -0
SimpleRule34/main.py
CHANGED
|
@@ -17,7 +17,7 @@ class Rule34BaseApi:
|
|
|
17
17
|
**kwargs,
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
async def _get(self, json_: bool = True, **params) -> dict | str:
|
|
20
|
+
async def _get(self, json_: bool = True, **params) -> dict | str | None:
|
|
21
21
|
"""
|
|
22
22
|
Raw request method
|
|
23
23
|
|
|
@@ -29,8 +29,10 @@ class Rule34BaseApi:
|
|
|
29
29
|
|
|
30
30
|
async with aiohttp.ClientSession(headers=self._header) as session:
|
|
31
31
|
async with session.get(self._url, params={**self._params, **params, 'json': json_parsed}) as response:
|
|
32
|
-
if not response.ok:
|
|
32
|
+
if not response.ok and response.status not in [404, ]:
|
|
33
33
|
raise ApiException(await response.text())
|
|
34
|
+
elif response.status == 404:
|
|
35
|
+
return None
|
|
34
36
|
|
|
35
37
|
# Used for handling XML response
|
|
36
38
|
if not json_:
|
|
@@ -47,7 +49,7 @@ class Rule34PostApi(Rule34BaseApi):
|
|
|
47
49
|
super().__init__(user_id, api_key, **kwargs)
|
|
48
50
|
self._params['s'] = "post"
|
|
49
51
|
|
|
50
|
-
async def get(self, id: int) -> Rule34Post:
|
|
52
|
+
async def get(self, id: int) -> Rule34Post | None:
|
|
51
53
|
"""
|
|
52
54
|
Method used to obtain a post by its ID
|
|
53
55
|
|
|
@@ -56,7 +58,7 @@ class Rule34PostApi(Rule34BaseApi):
|
|
|
56
58
|
"""
|
|
57
59
|
|
|
58
60
|
post = await self._get(id=id)
|
|
59
|
-
return Rule34Post(**post[0])
|
|
61
|
+
return Rule34Post(**post[0]) if post else None
|
|
60
62
|
|
|
61
63
|
async def get_count(self, tags: list[str] = None) -> int:
|
|
62
64
|
"""
|
|
@@ -96,6 +98,8 @@ class Rule34PostApi(Rule34BaseApi):
|
|
|
96
98
|
raise ValueError(f"The max size of request is 1000 when you tried to request {amount}")
|
|
97
99
|
|
|
98
100
|
raw_list = await self._get(limit=amount, pid=page, tags=" ".join(tags))
|
|
101
|
+
if raw_list is None: return []
|
|
102
|
+
|
|
99
103
|
post_list = [Rule34Post(**data) for data in raw_list]
|
|
100
104
|
|
|
101
105
|
# Fast return if not sort is needed
|
|
@@ -126,6 +130,8 @@ class Rule34CommentsApi(Rule34BaseApi):
|
|
|
126
130
|
"""
|
|
127
131
|
|
|
128
132
|
xml_data = await self._get(post_id=post_id, json_=False)
|
|
133
|
+
if xml_data is None: return []
|
|
134
|
+
|
|
129
135
|
xml_root = ET.fromstring(xml_data)
|
|
130
136
|
|
|
131
137
|
return [Rule34Comment(**comment_e.attrib) for comment_e in xml_root.findall("comment")]
|
|
@@ -145,6 +151,8 @@ class Rule34TagsApi(Rule34BaseApi):
|
|
|
145
151
|
"""
|
|
146
152
|
|
|
147
153
|
xml_data = await self._get(id=id, json_=False)
|
|
154
|
+
if xml_data is None: return None
|
|
155
|
+
|
|
148
156
|
xml_root = ET.fromstring(xml_data)
|
|
149
157
|
|
|
150
158
|
raw_tag_data = xml_root.find("tag")
|
|
@@ -162,6 +170,8 @@ class Rule34TagsApi(Rule34BaseApi):
|
|
|
162
170
|
"""
|
|
163
171
|
|
|
164
172
|
xml_data = await self._get(json_=False, limit=amount, pid=page)
|
|
173
|
+
if xml_data is None: return []
|
|
174
|
+
|
|
165
175
|
xml_root = ET.fromstring(xml_data)
|
|
166
176
|
|
|
167
177
|
return [Rule34Tag(**tag_e.attrib) for tag_e in xml_root.findall("tag")]
|
SimpleRule34/types.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import typing
|
|
3
3
|
import re
|
|
4
|
+
import warnings
|
|
4
5
|
|
|
5
6
|
from enum import Enum
|
|
6
7
|
from pathlib import Path
|
|
@@ -23,9 +24,12 @@ class File(BaseModel):
|
|
|
23
24
|
|
|
24
25
|
self.type = get_file_type(str(self.url))
|
|
25
26
|
|
|
26
|
-
async def download(self, path: Path | str = "./rule34_downloads") -> Path:
|
|
27
|
+
async def download(self, path: Path | str = "./rule34_downloads", file_name: Path | str = None) -> Path:
|
|
27
28
|
if isinstance(path, str):
|
|
28
29
|
path = Path(path)
|
|
30
|
+
if isinstance(file_name, str):
|
|
31
|
+
file_name = Path(file_name)
|
|
32
|
+
|
|
29
33
|
# Create storage path
|
|
30
34
|
path.mkdir(parents=True, exist_ok=True)
|
|
31
35
|
|
|
@@ -35,7 +39,11 @@ class File(BaseModel):
|
|
|
35
39
|
raise ApiException(f"Api returned status code {response.status} with message"
|
|
36
40
|
f" {await response.text()}")
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
original_file_name = Path(os.path.basename(str(self.url)))
|
|
43
|
+
file_name = original_file_name if file_name is None else file_name
|
|
44
|
+
if file_name.suffix != original_file_name.suffix:
|
|
45
|
+
warnings.warn("Provided file name suffix does not match original file name suffix. File can be corrupted.")
|
|
46
|
+
|
|
39
47
|
save_path = path / file_name
|
|
40
48
|
|
|
41
49
|
async with aiofiles.open(save_path, 'wb') as file:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simple_rule34
|
|
3
|
-
Version: 1.0.0.
|
|
3
|
+
Version: 1.0.0.2
|
|
4
4
|
Summary: Simple api wrapper of rule34.xxx for python with asynchronous support
|
|
5
5
|
Author-email: StarMan12 <author@example.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/SyperAlexKomp/simple-rule34-api
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
SimpleRule34/__init__.py,sha256=9VMHjQsFOoSFNj_Ufq6VJLcTXHJPvqxeEozHpIpXSe0,29
|
|
3
|
+
SimpleRule34/exceptions.py,sha256=7tjDPPoOmXTBaMbfsSjaLsXkzgChdKLBsDyCMClMIAo,341
|
|
4
|
+
SimpleRule34/main.py,sha256=zo5AljPUxhLrRI0AddZWJyRRHVW8zzVFFaC3zyQc2ZE,7396
|
|
5
|
+
SimpleRule34/types.py,sha256=RBX7Wt26Q1vffVKF1kaHd5ivhk4o_p5kN4dprZ36s6w,3554
|
|
6
|
+
SimpleRule34/utils.py,sha256=q4ohygRV4J88mNUQnCQ_-_A2-syIZpnO_UifIt_vpFc,689
|
|
7
|
+
simple_rule34-1.0.0.2.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
8
|
+
simple_rule34-1.0.0.2.dist-info/METADATA,sha256=n4Btg9_qPZhURUUaThW23UOtiT6asSGModOzfUTagJY,801
|
|
9
|
+
simple_rule34-1.0.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
10
|
+
simple_rule34-1.0.0.2.dist-info/top_level.txt,sha256=YI-Z1ijzIjlJw2WeM95PSmClCzIvm24KAlyZi80YVNs,22
|
|
11
|
+
simple_rule34-1.0.0.2.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
SimpleRule34/__init__.py,sha256=9VMHjQsFOoSFNj_Ufq6VJLcTXHJPvqxeEozHpIpXSe0,29
|
|
3
|
-
SimpleRule34/exceptions.py,sha256=7tjDPPoOmXTBaMbfsSjaLsXkzgChdKLBsDyCMClMIAo,341
|
|
4
|
-
SimpleRule34/main.py,sha256=L_JIw45Y8UcBWiRvmeeB5zSimjHLOjVoNf1Hg29rMKY,7080
|
|
5
|
-
SimpleRule34/types.py,sha256=6yHumh_U2khFmxgBzVyz2Hj81kdH-z6vCOqfoPHyj0k,3127
|
|
6
|
-
SimpleRule34/utils.py,sha256=q4ohygRV4J88mNUQnCQ_-_A2-syIZpnO_UifIt_vpFc,689
|
|
7
|
-
simple_rule34-1.0.0.0.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
8
|
-
simple_rule34-1.0.0.0.dist-info/METADATA,sha256=gh6Aa2UwAXDGHe3uSYxP24r1NnrdqKcZmMEXayx0DdE,801
|
|
9
|
-
simple_rule34-1.0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
-
simple_rule34-1.0.0.0.dist-info/top_level.txt,sha256=YI-Z1ijzIjlJw2WeM95PSmClCzIvm24KAlyZi80YVNs,22
|
|
11
|
-
simple_rule34-1.0.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|