Skip to content

Commit

Permalink
Simplify queries for the dimension endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
leonghui committed Jan 20, 2024
1 parent 7593c9e commit fd58018
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
9 changes: 2 additions & 7 deletions amazon_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,14 @@ def get_search_results(search_query):
def get_dimension_url(listing_query, item_id):
# Call the "dimension" endpoint which is used on mobile pages
# to display price and availability for product variants
#
# Use a pair of ASINs with a valid parent-child relationship
# to trigger a response

locale_data = listing_query.locale
base_url = "https://" + locale_data.domain
dimension_endpoint = base_url + "/gp/twister/dimension?"

query_dict = {
"asinList": locale_data.child_asin + "," + item_id,
"productTypeDefinition": None,
"productGroupId": locale_data.product_group,
"parentAsin": locale_data.parent_asin,
"asinList": item_id,
"parentAsin": item_id,
}

return dimension_endpoint + urlencode(query_dict)
Expand Down
16 changes: 0 additions & 16 deletions amazon_feed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,29 @@ class AmazonLocale:
domain: str
unavailable_text: UnavailabilityText
option_pattern: OptionPatterns
child_asin: str
parent_asin: str
product_group: str

def __hash__(self):
return hash(self.code)


# requires valid child_asin, parent_asin, and product_group for item dimension endpoint
locale_list = [
AmazonLocale(
"AU",
"www.amazon.com.au",
UnavailabilityText.EN,
OptionPatterns.EN,
"B08N3J8GTX",
"B0BCMPYWKN",
"amazon_ereaders_display_on_website",
),
AmazonLocale(
"SG",
"www.amazon.sg",
UnavailabilityText.EN,
OptionPatterns.EN,
"B09SWTG9GF",
"B0BCSYDF82",
"amazon_devices_display_on_website",
),
AmazonLocale(
"UK",
"www.amazon.co.uk",
UnavailabilityText.EN,
OptionPatterns.EN,
"B08N36XNTT",
"B0BF6HS47P",
"amazon_ereaders_display_on_website",
),
]

Expand All @@ -63,9 +50,6 @@ def __hash__(self):
"www.amazon.com",
UnavailabilityText.EN,
OptionPatterns.EN,
"B09TMK7QFX",
"B0BCTGXVB2",
"amazon_ereaders_display_on_website",
)

locale_list.append(default_locale)
Expand Down

0 comments on commit fd58018

Please sign in to comment.