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 diff --git a/src/parsing/ozon_parser.py b/src/parsing/ozon_parser.py index bd29990..fd2788b 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,22 @@ def get_items(urls: OzonUrls) -> list[OzonItemPair]: return items @staticmethod + def return_error_item_on_exception(func): + def get_item(url: str): + try: + item = func(url) + except Exception: + item = OzonItem( + url=url, + status=Status.PARSING_ERROR + ) + return item + + return get_item + + @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}...") diff --git a/src/sheets/wildberries_sheets.py b/src/sheets/wildberries_sheets.py index 18abd41..97bd252 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=8) logger.debug("Merging cells...") - self._sheet.merge_cells("F1:H1") + self._sheet.merge_cells("G1:I1")