simple-rule34 1.0.0.1__py3-none-any.whl → 1.0.0.3__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
  """
@@ -71,6 +73,8 @@ class Rule34PostApi(Rule34BaseApi):
71
73
  tags = []
72
74
 
73
75
  xml_data = await self._get(json_=False, tags=" ".join(tags))
76
+ if xml_data is None: return 0
77
+
74
78
  xml_root = ET.fromstring(xml_data)
75
79
 
76
80
  return int(xml_root.get('count'))
@@ -96,6 +100,8 @@ class Rule34PostApi(Rule34BaseApi):
96
100
  raise ValueError(f"The max size of request is 1000 when you tried to request {amount}")
97
101
 
98
102
  raw_list = await self._get(limit=amount, pid=page, tags=" ".join(tags))
103
+ if raw_list is None: return []
104
+
99
105
  post_list = [Rule34Post(**data) for data in raw_list]
100
106
 
101
107
  # Fast return if not sort is needed
@@ -126,6 +132,8 @@ class Rule34CommentsApi(Rule34BaseApi):
126
132
  """
127
133
 
128
134
  xml_data = await self._get(post_id=post_id, json_=False)
135
+ if xml_data is None: return []
136
+
129
137
  xml_root = ET.fromstring(xml_data)
130
138
 
131
139
  return [Rule34Comment(**comment_e.attrib) for comment_e in xml_root.findall("comment")]
@@ -145,6 +153,8 @@ class Rule34TagsApi(Rule34BaseApi):
145
153
  """
146
154
 
147
155
  xml_data = await self._get(id=id, json_=False)
156
+ if xml_data is None: return None
157
+
148
158
  xml_root = ET.fromstring(xml_data)
149
159
 
150
160
  raw_tag_data = xml_root.find("tag")
@@ -162,6 +172,8 @@ class Rule34TagsApi(Rule34BaseApi):
162
172
  """
163
173
 
164
174
  xml_data = await self._get(json_=False, limit=amount, pid=page)
175
+ if xml_data is None: return []
176
+
165
177
  xml_root = ET.fromstring(xml_data)
166
178
 
167
179
  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.3
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=cT2Gif-EL-RPd9pgPD27xa0v98-TIEGq30BhAzbC7lc,7437
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.3.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
8
+ simple_rule34-1.0.0.3.dist-info/METADATA,sha256=ELLR4Lm0qpDFqEp99KWlApSVVhHVq9KLml5Epw_QW6I,801
9
+ simple_rule34-1.0.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
10
+ simple_rule34-1.0.0.3.dist-info/top_level.txt,sha256=YI-Z1ijzIjlJw2WeM95PSmClCzIvm24KAlyZi80YVNs,22
11
+ simple_rule34-1.0.0.3.dist-info/RECORD,,