From 27ef25a46c2f83fa6877d684a2d112fbe83746a6 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 2 Apr 2024 14:46:12 +0300 Subject: [PATCH 1/5] req: add the retry lib --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0a7c1b7..b1ccd70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ gspread==5.3.2 oauth2client==4.1.3 schedule==1.1.0 coloredlogs==15.0.1 -undetected-chromedriver==3.5.4 \ No newline at end of file +undetected-chromedriver==3.5.4 +the-retry==0.1.1 \ No newline at end of file From 77e69eb10f446dcf66dc0de48b737273315b232d Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 2 Apr 2024 14:46:26 +0300 Subject: [PATCH 2/5] fix: add retry on parsing exception --- src/parsing/ozon_parser.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/parsing/ozon_parser.py b/src/parsing/ozon_parser.py index bd29990..4c8357f 100644 --- a/src/parsing/ozon_parser.py +++ b/src/parsing/ozon_parser.py @@ -2,6 +2,7 @@ import re from requests import Session +from the_retry import retry from src.models import Status, OzonUrls, OzonItemPair, OzonItem from src.parsing import ItemParser @@ -88,6 +89,21 @@ def get_items(urls: OzonUrls) -> list[OzonItemPair]: return items @staticmethod + def return_error_item_on_exception(func): + def wrapper(*arg, **kwargs): + try: + func(*arg, **kwargs) + except Exception: + return OzonItem( + url=arg[0], + status=Status.PARSING_ERROR + ) + + return wrapper + + @staticmethod + @return_error_item_on_exception + @retry(attempts=3, backoff=1, exponential_backoff=True) def _get_item(url: str) -> OzonItem | None: logger.info(f"Getting item from: {url}...") From 22d05fd9f1c6491b774466c52ffb0ca180e63df9 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 2 Apr 2024 14:54:19 +0300 Subject: [PATCH 3/5] fix: add return from get item --- src/parsing/ozon_parser.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/parsing/ozon_parser.py b/src/parsing/ozon_parser.py index 4c8357f..fd2788b 100644 --- a/src/parsing/ozon_parser.py +++ b/src/parsing/ozon_parser.py @@ -90,16 +90,17 @@ def get_items(urls: OzonUrls) -> list[OzonItemPair]: @staticmethod def return_error_item_on_exception(func): - def wrapper(*arg, **kwargs): + def get_item(url: str): try: - func(*arg, **kwargs) + item = func(url) except Exception: - return OzonItem( - url=arg[0], + item = OzonItem( + url=url, status=Status.PARSING_ERROR ) + return item - return wrapper + return get_item @staticmethod @return_error_item_on_exception From 3a3d52e6ad8352a919c198f45bbc5f4d53624a5f Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 2 Apr 2024 16:11:34 +0300 Subject: [PATCH 4/5] fix: move wb sheets by 1 --- src/sheets/wildberries_sheets.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sheets/wildberries_sheets.py b/src/sheets/wildberries_sheets.py index 18abd41..cae6637 100644 --- a/src/sheets/wildberries_sheets.py +++ b/src/sheets/wildberries_sheets.py @@ -53,20 +53,20 @@ def set_items(self, items: List[WildberriesItem]): sales.append("") logger.debug("Removing previous colors...") - self._remove_formatting(f"G2:G{len(urls) + 1}") + self._remove_formatting(f"H2:H{len(urls) + 1}") logger.debug("Inserting data...") - self._sheet.insert_cols([quantities, prices, sales], col=6, value_input_option=ValueInputOption.user_entered) + self._sheet.insert_cols([quantities, prices, sales], col=7, value_input_option=ValueInputOption.user_entered) logger.debug("Adding borders...") - self._add_border(f"F1:H{len(urls) + 1}") + self._add_border(f"G1:I{len(urls) + 1}") logger.debug("Formatting numbers...") - self._format_cells(f"F2:G{len(urls) + 1}", CellFormat.NUMBER_WITH_SPACE) - self._format_cells(f"H2:H{len(urls) + 1}", CellFormat.NUMBER_PERCENT) + self._format_cells(f"G2:H{len(urls) + 1}", CellFormat.NUMBER_WITH_SPACE) + self._format_cells(f"I2:I{len(urls) + 1}", CellFormat.NUMBER_PERCENT) logger.debug("Coloring red cells...") - self._color_red_cells(f"G2:G{len(urls) + 1}", restrictions_col=3, prices_col=5) + self._color_red_cells(f"H2:H{len(urls) + 1}", restrictions_col=3, prices_col=5) logger.debug("Merging cells...") - self._sheet.merge_cells("F1:H1") + self._sheet.merge_cells("G1:I1") From 538f2242a938a92e5c9b45d20eb5c17381aa936a Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 2 Apr 2024 16:16:03 +0300 Subject: [PATCH 5/5] fix: add correct price column --- src/sheets/wildberries_sheets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sheets/wildberries_sheets.py b/src/sheets/wildberries_sheets.py index cae6637..97bd252 100644 --- a/src/sheets/wildberries_sheets.py +++ b/src/sheets/wildberries_sheets.py @@ -66,7 +66,7 @@ def set_items(self, items: List[WildberriesItem]): self._format_cells(f"I2:I{len(urls) + 1}", CellFormat.NUMBER_PERCENT) logger.debug("Coloring red cells...") - self._color_red_cells(f"H2:H{len(urls) + 1}", restrictions_col=3, prices_col=5) + self._color_red_cells(f"H2:H{len(urls) + 1}", restrictions_col=3, prices_col=8) logger.debug("Merging cells...") self._sheet.merge_cells("G1:I1")