Ejemplo n.º 1
0
def price_range(manufacturer, low_price, high_price):
    """Handle requests to search by price range.
    We actually search the database for products from *manufacturer*
    within *user_input* values.

    :param str user_input: prices separated by comma.
    :param str manufacturer: the manufacturer to search.
    """
    response = Response()
    flow, fhigh = get_prices(low_price, high_price)
    # get products from database
    our_products = query_price_range_search_db(
        manufacturer,
        flow,
        fhigh
    )
    # Amazon only allows 10 upcs at a time.
    upc_sectioned_list = sectionize_upcs(our_products)
    for upcs in upc_sectioned_list:
        try:
            products = amazon_api.product_lookup('UPC', upcs)
        except:
            print('Unable to process {0}'.format(upcs))
            # TODO: currently we just throw away the whole section of UPCS
            # we should just filtered out the bad UPC and try again.
            continue
        populate_response_listings(products, response)
    listings = response.listings
    add_listings_to_db(listings)
    return save_listings_to_result(listings)
Ejemplo n.º 2
0
def price_range(manufacturer, low_price, high_price):
    """Handle requests to search by price range.
    We actually search the database for products from *manufacturer*
    within *user_input* values.

    :param str user_input: prices separated by comma.
    :param str manufacturer: the manufacturer to search.
    """
    response = Response()
    flow, fhigh = get_prices(low_price, high_price)
    # get products from database
    our_products = query_price_range_search_db(manufacturer, flow, fhigh)
    # Amazon only allows 10 upcs at a time.
    upc_sectioned_list = sectionize_upcs(our_products)
    for upcs in upc_sectioned_list:
        try:
            products = amazon_api.product_lookup('UPC', upcs)
        except:
            print('Unable to process {0}'.format(upcs))
            # TODO: currently we just throw away the whole section of UPCS
            # we should just filtered out the bad UPC and try again.
            continue
        populate_response_listings(products, response)
    listings = response.listings
    add_listings_to_db(listings)
    return save_listings_to_result(listings)
Ejemplo n.º 3
0
def itemlookup(search_by, user_input):
    """Handle request to Amazon's PAAPI lookup.
    Currently the user can search by ASIN and UPC.

    :param str search_by: earch by Criteria UPC or ASIN.
    :param str user_input: upc(s)/asin(s).
    """
    response = Response()
    try:
        products = amazon_api.product_lookup(search_by, user_input)
    except:
        print('Unable to process {0}'.format(user_input))
        return save_listings_to_result({}, errors="Unable to perform search")
    populate_response_listings(products, response)
    listings = response.listings
    add_listings_to_db(listings)
    return save_listings_to_result(listings)
Ejemplo n.º 4
0
def itemlookup(search_by, user_input):
    """Handle request to Amazon's PAAPI lookup.
    Currently the user can search by ASIN and UPC.

    :param str search_by: earch by Criteria UPC or ASIN.
    :param str user_input: upc(s)/asin(s).
    """
    response = Response()
    try:
        products = amazon_api.product_lookup(search_by, user_input)
    except:
        print('Unable to process {0}'.format(user_input))
        return save_listings_to_result(
            {},
            errors="Unable to perform search"
        )
    populate_response_listings(products, response)
    listings = response.listings
    add_listings_to_db(listings)
    return save_listings_to_result(listings)