drop EXPECTED_TASK_ERRORS wrappers in category fetch; finish monitor kwarg rename
The add_products_to_database call still passed monitor_name after the previous commit because its hunk sat inside this larger edit. It now passes monitor, matching the monitor_utils signature.
This commit is contained in:
1 parent
f5b3ce997f
commit
c6c606b504
1 file changed
+39
-53
@@ -4,7 +4,7 @@ from urllib.parse import urlencode
|
|||||||
|
|
||||||
from aioweb_tls import TLSSession
|
from aioweb_tls import TLSSession
|
||||||
from monitor_utils.config import DevelopmentMode
|
from monitor_utils.config import DevelopmentMode
|
||||||
from monitor_utils.constants import CYCLE_DELAY, EXPECTED_TASK_ERRORS
|
from monitor_utils.constants import CYCLE_DELAY
|
||||||
from monitor_utils.database import add_products_to_database
|
from monitor_utils.database import add_products_to_database
|
||||||
from monitor_utils.models import AvailabilityInfo, PricingInfo, Product, ProductMetadata
|
from monitor_utils.models import AvailabilityInfo, PricingInfo, Product, ProductMetadata
|
||||||
from monitor_utils.runner import (
|
from monitor_utils.runner import (
|
||||||
@@ -53,32 +53,25 @@ async def get_category_products(
|
|||||||
offset=0,
|
offset=0,
|
||||||
):
|
):
|
||||||
LOGGER.debug("getting products", extra={"category": category_id, "offset": offset})
|
LOGGER.debug("getting products", extra={"category": category_id, "offset": offset})
|
||||||
try:
|
response = await send_request(
|
||||||
response = await send_request(
|
session,
|
||||||
session,
|
url="https://sribsrch.ecom.samsung.com/estoresearch-api/v1/scom/us/pf_search",
|
||||||
url="https://sribsrch.ecom.samsung.com/estoresearch-api/v1/scom/us/pf_search",
|
method="POST",
|
||||||
method="POST",
|
data=urlencode(
|
||||||
data=urlencode(
|
{
|
||||||
{
|
"clientCode": "b2c",
|
||||||
"clientCode": "b2c",
|
"clientName": "scom_pf",
|
||||||
"clientName": "scom_pf",
|
"firstSearchYN": "true",
|
||||||
"firstSearchYN": "true",
|
"countryCode": "us",
|
||||||
"countryCode": "us",
|
"storeID": "us_education",
|
||||||
"storeID": "us_education",
|
"startIndex": str(offset),
|
||||||
"startIndex": str(offset),
|
"requestCount": str(PRODUCTS_PER_PAGE),
|
||||||
"requestCount": str(PRODUCTS_PER_PAGE),
|
"category_code": category_id,
|
||||||
"category_code": category_id,
|
"sort": "newest",
|
||||||
"sort": "newest",
|
}
|
||||||
}
|
),
|
||||||
),
|
headers={"content-type": "application/x-www-form-urlencoded"},
|
||||||
headers={"content-type": "application/x-www-form-urlencoded"},
|
)
|
||||||
)
|
|
||||||
except EXPECTED_TASK_ERRORS:
|
|
||||||
LOGGER.warning(
|
|
||||||
"failed to get products",
|
|
||||||
extra={"category": category_id, "offset": offset},
|
|
||||||
)
|
|
||||||
raise
|
|
||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if offset != 0:
|
if offset != 0:
|
||||||
@@ -114,34 +107,27 @@ async def process_page(
|
|||||||
):
|
):
|
||||||
"""Extract and persist one page of category search results."""
|
"""Extract and persist one page of category search results."""
|
||||||
|
|
||||||
try:
|
products = extract_products(response)
|
||||||
products = extract_products(response)
|
if products:
|
||||||
if products:
|
await add_products_to_database(
|
||||||
await add_products_to_database(
|
products,
|
||||||
products,
|
collection,
|
||||||
collection,
|
category_identifier=category_id,
|
||||||
category_identifier=category_id,
|
monitor="samsung_shop",
|
||||||
monitor_name="samsung_shop",
|
)
|
||||||
)
|
LOGGER.info(
|
||||||
LOGGER.info(
|
"added products",
|
||||||
"added products",
|
extra={
|
||||||
extra={
|
"category": category_id,
|
||||||
"category": category_id,
|
"offset": offset,
|
||||||
"offset": offset,
|
"count": len(products),
|
||||||
"count": len(products),
|
},
|
||||||
},
|
)
|
||||||
)
|
else:
|
||||||
else:
|
LOGGER.debug(
|
||||||
LOGGER.debug(
|
"no products found",
|
||||||
"no products found",
|
|
||||||
extra={"category": category_id, "offset": offset},
|
|
||||||
)
|
|
||||||
except EXPECTED_TASK_ERRORS:
|
|
||||||
LOGGER.warning(
|
|
||||||
"failed to build products",
|
|
||||||
extra={"category": category_id, "offset": offset},
|
extra={"category": category_id, "offset": offset},
|
||||||
)
|
)
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def extract_products(response: dict) -> list[Product]:
|
def extract_products(response: dict) -> list[Product]:
|
||||||
|
|||||||
Reference in new issue
Block a user