Skip to content

Commit

Permalink
Merge pull request #63 from TimNekk/develop
Browse files Browse the repository at this point in the history
Add some minor fixes
  • Loading branch information
TimNekk authored Apr 2, 2024
2 parents 313d34f + 538f224 commit 446558c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
undetected-chromedriver==3.5.4
the-retry==0.1.1
17 changes: 17 additions & 0 deletions src/parsing/ozon_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}...")

Expand Down
14 changes: 7 additions & 7 deletions src/sheets/wildberries_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 446558c

Please sign in to comment.