simple-rule34 1.0.0.1__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 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")]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple_rule34
3
- Version: 1.0.0.1
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
@@ -1,11 +1,11 @@
1
1
  __init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  SimpleRule34/__init__.py,sha256=9VMHjQsFOoSFNj_Ufq6VJLcTXHJPvqxeEozHpIpXSe0,29
3
3
  SimpleRule34/exceptions.py,sha256=7tjDPPoOmXTBaMbfsSjaLsXkzgChdKLBsDyCMClMIAo,341
4
- SimpleRule34/main.py,sha256=L_JIw45Y8UcBWiRvmeeB5zSimjHLOjVoNf1Hg29rMKY,7080
4
+ SimpleRule34/main.py,sha256=zo5AljPUxhLrRI0AddZWJyRRHVW8zzVFFaC3zyQc2ZE,7396
5
5
  SimpleRule34/types.py,sha256=RBX7Wt26Q1vffVKF1kaHd5ivhk4o_p5kN4dprZ36s6w,3554
6
6
  SimpleRule34/utils.py,sha256=q4ohygRV4J88mNUQnCQ_-_A2-syIZpnO_UifIt_vpFc,689
7
- simple_rule34-1.0.0.1.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
8
- simple_rule34-1.0.0.1.dist-info/METADATA,sha256=6y-CjmnUD6W_I6sGTvVPgoqFvxEl_yNU4akvec7RIvs,801
9
- simple_rule34-1.0.0.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
10
- simple_rule34-1.0.0.1.dist-info/top_level.txt,sha256=YI-Z1ijzIjlJw2WeM95PSmClCzIvm24KAlyZi80YVNs,22
11
- simple_rule34-1.0.0.1.dist-info/RECORD,,
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,,