simple-rule34 0.1.5.1__py3-none-any.whl → 0.1.5.4__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.
@@ -47,8 +47,10 @@ async def parse_result(post_element):
47
47
  return main_post, sample_post, preview_post
48
48
 
49
49
  class Rule34Api:
50
+ def __init__(self):
51
+ self.header = {'User-Agent': 'rule34-simple-api 0.1.5.3 (Request)'}
50
52
  async def get_post_count(self, tags: str = '') -> int:
51
- async with aiohttp.ClientSession() as session:
53
+ async with aiohttp.ClientSession(headers=self.header) as session:
52
54
  async with session.get(f'https://api.rule34.xxx/index.php?'
53
55
  f'page=dapi&s=post&q=index&tags={tags}') as response:
54
56
  xml_data = await response.text()
@@ -60,7 +62,7 @@ class Rule34Api:
60
62
  async def get_post(self, id: int):
61
63
  st = time.time()
62
64
 
63
- async with aiohttp.ClientSession() as session:
65
+ async with aiohttp.ClientSession(headers=self.header) as session:
64
66
  async with session.get(f'https://api.rule34.xxx/index.php?'
65
67
  f'page=dapi&s=post&q=index&id={id}') as response:
66
68
  xml_data = await response.text()
@@ -113,14 +115,19 @@ class Rule34Api:
113
115
  st = time.time()
114
116
 
115
117
  request_count = 1
118
+ true_count = count*20
116
119
 
117
120
  post_list = []
118
121
 
119
- if count > 1000:
120
- request_count = count // 1000
122
+ if true_count > 1000:
123
+ request_count = true_count // 1000
124
+
125
+ post_count = await self.get_post_count(tags)
126
+ page_id = int(random.randint(0, int(post_count / true_count)) / 8) if post_count >= true_count else 0
121
127
 
122
128
  for pid in range(request_count + 1):
123
- post_list += await self.get_post_list(tags=tags, forbidden_tags=forbidden_tags)
129
+ post_list += await self.get_post_list(tags=tags, forbidden_tags=forbidden_tags,
130
+ page_id=page_id, limit=true_count if true_count <= 1000 else 1000)
124
131
 
125
132
  getted = []
126
133
 
@@ -136,7 +143,7 @@ class Rule34Api:
136
143
 
137
144
  async def get_post_list(self, limit: int = 1000, page_id: int = 0, tags: str = '', forbidden_tags: list[str] = [])\
138
145
  -> list[Rule34PostData]:
139
- async with aiohttp.ClientSession() as session:
146
+ async with aiohttp.ClientSession(headers=self.header) as session:
140
147
  if limit > 1000:
141
148
  raise ToBigRequestException(f"The max size of request is 1000 when you tried to request {limit}")
142
149
 
SimpleRule34/aio/types.py CHANGED
@@ -1,4 +1,6 @@
1
1
  import typing
2
+
3
+ import aiofiles
2
4
  import aiohttp
3
5
  import os
4
6
  import datetime
@@ -34,8 +36,8 @@ class Rule34Post:
34
36
 
35
37
  file_name = os.path.basename(self.url)
36
38
  save_path = os.path.join(path, file_name)
37
- with open(save_path, 'wb') as file:
38
- file.write(await response.read())
39
+ with aiofiles.open(save_path, 'wb') as file:
40
+ await file.write(await response.read())
39
41
 
40
42
  return save_path
41
43
  else:
SimpleRule34/types.py CHANGED
@@ -6,9 +6,9 @@ from .utils import get_file_type, get_file_size
6
6
 
7
7
 
8
8
  class Rule34Post:
9
- def __init__(self, height: int, width: int, url: str, id: int, session: requests.Session):
9
+ def __init__(self, height: int, width: int, url: str, id: int):
10
10
  self.path = r'./rule34_download'
11
- self.s = session
11
+ self.s = requests.Session()
12
12
 
13
13
  self.height = height
14
14
  self.width = width
@@ -49,8 +49,8 @@ class Rule34Post:
49
49
  class Rule34MainPost(Rule34Post):
50
50
  def __init__(self, score: int, rating: str, creator_id: int, tags: str, has_children: bool,
51
51
  created_date: datetime.datetime, status: str, source: str, has_notes: bool, has_comments: bool,
52
- height: int, width: int, url: str, id: int, s):
53
- super().__init__(height, width, url, id, s)
52
+ height: int, width: int, url: str, id: int):
53
+ super().__init__(height, width, url, id)
54
54
  self.score = score
55
55
  self.rating = rating
56
56
  self.creator_id = creator_id
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
- Name: simple-rule34
3
- Version: 0.1.5.1
2
+ Name: simple_rule34
3
+ Version: 0.1.5.4
4
4
  Summary: Simple api wrapper of rule34.xxx for python with asynchronous support
5
5
  Author-email: StarMan12 <author@example.com>
6
- Project-URL: Homepage, https://github.com/Loshok229/rule34-simple-api
7
- Project-URL: Bug Tracker, https://github.com/Loshok229/rule34-simple-api/issues
6
+ Project-URL: Homepage, https://github.com/SyperAlexKomp/simple-rule34-api
7
+ Project-URL: Bug Tracker, https://github.com/SyperAlexKomp/simple-rule34-api/issues
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
@@ -0,0 +1,14 @@
1
+ SimpleRule34/Rule34.py,sha256=3eMo_5a20g8eQVlSwm3EBJVZVlxdiB354EejMRWnqMs,7136
2
+ SimpleRule34/__init__.py,sha256=C4IbcJ_rjqBhpENXImVGuEQxf81GUwNaycqNNAY_ROc,31
3
+ SimpleRule34/exceptions.py,sha256=8MbvBbdb254UaYWfPg3xo_GbSDO6L9iI0d2AFaet9AM,354
4
+ SimpleRule34/setup.py,sha256=7hNDTD52EAs7W00-Nd5LzvH8H4-Dvc59W8a999LqvW4,735
5
+ SimpleRule34/types.py,sha256=PpIHfMlFfRvXAZ_0Seaj9HJH6f_9JpJHCELIoSbeyuo,3278
6
+ SimpleRule34/utils.py,sha256=lVbM6w2z9QwdOhVpff4q73_DfPLxDEXPVlxI2M6aK6I,854
7
+ SimpleRule34/aio/ARule34.py,sha256=nZwxmMNo_g_a16U9dJmxFGUIkDtgNB-W0uFH8LJ8tSI,6858
8
+ SimpleRule34/aio/types.py,sha256=XvhZAYG7AzrT2iKRVlXGwS_EIqrn406vG7P2OnPfcx8,3713
9
+ SimpleRule34/aio/utils.py,sha256=fWx-ntJ672NoktH5Ws9-FcO0gtCNVmd8VfxFxjWqsD0,616
10
+ simple_rule34-0.1.5.4.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
11
+ simple_rule34-0.1.5.4.dist-info/METADATA,sha256=23_XOZltBacTOjrNr1vyGPLYGr7FwneROn_kRmEBaE4,2089
12
+ simple_rule34-0.1.5.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
+ simple_rule34-0.1.5.4.dist-info/top_level.txt,sha256=IrrcPxvAx-V0ikmhRaLYkjYt-hZ9SRGTcUdtAcbMzGE,13
14
+ simple_rule34-0.1.5.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.1)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,14 +0,0 @@
1
- SimpleRule34/Rule34.py,sha256=3eMo_5a20g8eQVlSwm3EBJVZVlxdiB354EejMRWnqMs,7136
2
- SimpleRule34/__init__.py,sha256=C4IbcJ_rjqBhpENXImVGuEQxf81GUwNaycqNNAY_ROc,31
3
- SimpleRule34/exceptions.py,sha256=8MbvBbdb254UaYWfPg3xo_GbSDO6L9iI0d2AFaet9AM,354
4
- SimpleRule34/setup.py,sha256=7hNDTD52EAs7W00-Nd5LzvH8H4-Dvc59W8a999LqvW4,735
5
- SimpleRule34/types.py,sha256=kkdd__XAC3-7rvmekfNnwudM8Lhqmk0914xAcgII1Eg,3300
6
- SimpleRule34/utils.py,sha256=lVbM6w2z9QwdOhVpff4q73_DfPLxDEXPVlxI2M6aK6I,854
7
- SimpleRule34/aio/ARule34.py,sha256=cUFEqDL84qCQ3R9B3W-75l7Cu9st21GbcExvkqvENh0,6372
8
- SimpleRule34/aio/types.py,sha256=1FvHd8ZXaUu6hoJIptPbBTXCPgZlk6MlOyR7CQWhxvQ,3679
9
- SimpleRule34/aio/utils.py,sha256=fWx-ntJ672NoktH5Ws9-FcO0gtCNVmd8VfxFxjWqsD0,616
10
- simple_rule34-0.1.5.1.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
11
- simple_rule34-0.1.5.1.dist-info/METADATA,sha256=jiap6exu3JxysMG8MRHdwRJ2z0-xZ5ncm_X6K1fZ6iw,2081
12
- simple_rule34-0.1.5.1.dist-info/WHEEL,sha256=5sUXSg9e4bi7lTLOHcm6QEYwO5TIF1TNbTSVFVjcJcc,92
13
- simple_rule34-0.1.5.1.dist-info/top_level.txt,sha256=IrrcPxvAx-V0ikmhRaLYkjYt-hZ9SRGTcUdtAcbMzGE,13
14
- simple_rule34-0.1.5.1.dist-info/RECORD,,