Compare commits

..
2 Commits
Author SHA1 Message Date
TPV 4dd4494435 use get_response_json in get_category_products
Adds the body guard this site lacked; a non-dict body now logs and
returns before the fan-out instead of raising on searchTotalCount.
2026-09-26 10:30:02 -07:00
TPV c6c606b504 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.
2026-09-25 19:09:05 -07:00
+9 -18
View File
@@ -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 (
@@ -14,7 +14,7 @@ from monitor_utils.runner import (
run_bounded_cycle, run_bounded_cycle,
setup_monitor_logging, setup_monitor_logging,
) )
from monitor_utils.sessions import send_request from monitor_utils.sessions import get_response_json, send_request
from motor.motor_asyncio import AsyncIOMotorCollection from motor.motor_asyncio import AsyncIOMotorCollection
setup_monitor_logging(monitor="samsung_shop") setup_monitor_logging(monitor="samsung_shop")
@@ -53,7 +53,6 @@ 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",
@@ -73,14 +72,13 @@ async def get_category_products(
), ),
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 = get_response_json(
response, logger=LOGGER, category=category_id, offset=offset
)
if data is None:
return
if offset != 0: if offset != 0:
await process_page(data, category_id, offset, collection) await process_page(data, category_id, offset, collection)
return return
@@ -114,14 +112,13 @@ 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_name="samsung_shop", monitor="samsung_shop",
) )
LOGGER.info( LOGGER.info(
"added products", "added products",
@@ -136,12 +133,6 @@ async def process_page(
"no products found", "no products found",
extra={"category": category_id, "offset": offset}, extra={"category": category_id, "offset": offset},
) )
except EXPECTED_TASK_ERRORS:
LOGGER.warning(
"failed to build products",
extra={"category": category_id, "offset": offset},
)
raise
def extract_products(response: dict) -> list[Product]: def extract_products(response: dict) -> list[Product]: