Skip to content

Commit

Permalink
! Bulk Item parsing chunk size lowered
Browse files Browse the repository at this point in the history
  • Loading branch information
ALERTua committed Nov 20, 2023
1 parent e60937c commit c473f9c
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 41 deletions.
12 changes: 12 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ History
=======


1.2.0 (2023-10-20)
------------------

* Bulk Item parsing chunk size lowered


1.1.9 (2023-10-20)
------------------

* Pendulum version Bugfix


1.1.8 (2023-10-20)
------------------

Expand Down
205 changes: 168 additions & 37 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rozetka-api"
version = "1.1.9"
version = "1.2.0"
description = "Rozetka Python API"
authors = ["Alexey ALERT Rubasheff <alexey.rubasheff@gmail.com>"]
readme = "README.rst"
Expand Down
4 changes: 3 additions & 1 deletion rozetka/entities/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def subcategories(self):

if __name__ == '__main__':
LOG.verbose = True
category_ = Category.get(1162030)
category_ = Category.get(4658162)
iids = category_.items_ids
a = Item.parse_multiple(*iids, parse_subitems=False)
items_ = category_.items
pass
9 changes: 7 additions & 2 deletions rozetka/entities/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def _parse_batch(*product_ids, subitems=False, parse_subitems=True):
LOG.debug(f"Parsing batch of {len(product_ids)} products")
output = []
req = tools.get(url, params=params, headers=constants.DEFAULT_HEADERS)
if req.status_code != 200:
LOG.error(f"Error while parsing batch of {len(product_ids)} products: {req.status_code}: {req.reason}")
return output

if req is None:
return output

try:
data: List[dict] = req.json().get('data')
except Exception as e:
pass
data = []
"""
{
"id": 280528638,
Expand Down Expand Up @@ -227,9 +231,10 @@ def parse_multiple(*product_ids, subitems=False, parse_subitems=True):
product_ids = product_ids[0]

product_ids_str = [str(i) for i in product_ids]
chunk_size = 900
chunk_size = constants.BULK_ITEMS_REQUEST_MAX_LENGTH
chunked_lists = tools.slice_list(product_ids_str, chunk_size)
LOG.debug(f"Parsing {len(product_ids)} products divided into {len(chunked_lists)} batches by {chunk_size} each")
outputs = Item._parse_batch(*chunked_lists[0], subitems=subitems, parse_subitems=parse_subitems)
outputs = tools.fnc_map(Item._parse_batch, *chunked_lists, subitems=subitems, parse_subitems=parse_subitems)
outputs = [i for i in outputs if i]
output = []
Expand Down
1 change: 1 addition & 0 deletions rozetka/tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
DEFAULT_COOKIES = {
'visitor_city': "1",
}
BULK_ITEMS_REQUEST_MAX_LENGTH = 60

CALLS_MAX = int(os.getenv('CALLS_MAX', 10))
CALLS_PERIOD = int(os.getenv('CALLS_PERIOD', 1))
Expand Down

0 comments on commit c473f9c

Please sign in to comment.