Piero24 / TelegramBot-AmazonOffers

Receive alerts for the most irresistible Amazon offers straight to your Telegram, courtesy of our bot.
https://linktr.ee/webofferte
Apache License 2.0
2 stars 1 forks source link

Add a single product via ASIN #5

Open zird0t opened 1 month ago

zird0t commented 1 month ago

HI! Thanks for what you did. I was wondering: is it possible to completely exclude category searches, but add products directly via ASIN? I have readers who are only interested in a very narrow niche of products. Personally, I would add the ASIN list once a week, but there should be a method to schedule the posts.

Piero24 commented 1 month ago

Hi, No at the moment only category searching is supported. However, it is possible to modify the bot so that it searches for asin from a predefined list. It shouldn't be too complicated. You could use a function like this to send the request for specific asins:


def search_items_by_asin(access_key, secret_key, partner_tag, host, region, asin):

    item_property_dict = {}
    default_api = DefaultApi(access_key=access_key, secret_key=secret_key, host=host, region=region)
    item_ids = asin

    get_items_resource = [
        GetItemsResource.ITEMINFO_TITLE,
        GetItemsResource.OFFERS_LISTINGS_PRICE,
        GetItemsResource.IMAGES_PRIMARY_LARGE,
        GetItemsResource.OFFERS_LISTINGS_SAVINGBASIS,
        GetItemsResource.ITEMINFO_FEATURES,
        GetItemsResource.OFFERS_LISTINGS_PROMOTIONS,
        GetItemsResource.OFFERS_LISTINGS_CONDITION,
        GetItemsResource.OFFERS_LISTINGS_ISBUYBOXWINNER,
        GetItemsResource.OFFERS_SUMMARIES_LOWESTPRICE,
        GetItemsResource.OFFERS_SUMMARIES_HIGHESTPRICE,
        GetItemsResource.BROWSENODEINFO_BROWSENODES,
        GetItemsResource.BROWSENODEINFO_BROWSENODES_ANCESTOR,
        GetItemsResource.BROWSENODEINFO_BROWSENODES_SALESRANK,
        GetItemsResource.BROWSENODEINFO_WEBSITESALESRANK,
        GetItemsResource.ITEMINFO_BYLINEINFO,
        GetItemsResource.ITEMINFO_CLASSIFICATIONS,
        GetItemsResource.ITEMINFO_CONTENTINFO,
        GetItemsResource.ITEMINFO_CONTENTRATING,
        GetItemsResource.ITEMINFO_EXTERNALIDS,
        GetItemsResource.ITEMINFO_FEATURES,
        GetItemsResource.ITEMINFO_MANUFACTUREINFO,
        GetItemsResource.ITEMINFO_PRODUCTINFO,
        GetItemsResource.ITEMINFO_TECHNICALINFO,
        GetItemsResource.ITEMINFO_TRADEININFO,
        GetItemsResource.OFFERS_LISTINGS_AVAILABILITY_MAXORDERQUANTITY,
        GetItemsResource.OFFERS_LISTINGS_AVAILABILITY_MESSAGE,
        GetItemsResource.OFFERS_LISTINGS_AVAILABILITY_TYPE,
        GetItemsResource.OFFERS_LISTINGS_CONDITION,
        GetItemsResource.OFFERS_LISTINGS_AVAILABILITY_MINORDERQUANTITY,
        GetItemsResource.OFFERS_LISTINGS_CONDITION_SUBCONDITION,
        GetItemsResource.OFFERS_LISTINGS_DELIVERYINFO_ISAMAZONFULFILLED,
        GetItemsResource.OFFERS_LISTINGS_DELIVERYINFO_ISFREESHIPPINGELIGIBLE,
        GetItemsResource.OFFERS_LISTINGS_DELIVERYINFO_ISPRIMEELIGIBLE,
        GetItemsResource.OFFERS_LISTINGS_DELIVERYINFO_SHIPPINGCHARGES,
        GetItemsResource.OFFERS_LISTINGS_ISBUYBOXWINNER,
        GetItemsResource.OFFERS_LISTINGS_LOYALTYPOINTS_POINTS,
        GetItemsResource.OFFERS_LISTINGS_MERCHANTINFO,
        GetItemsResource.OFFERS_LISTINGS_PROGRAMELIGIBILITY_ISPRIMEEXCLUSIVE,
        GetItemsResource.OFFERS_LISTINGS_PROGRAMELIGIBILITY_ISPRIMEPANTRY,
        GetItemsResource.OFFERS_SUMMARIES_OFFERCOUNT,
        GetItemsResource.PARENTASIN,
        GetItemsResource.RENTALOFFERS_LISTINGS_AVAILABILITY_MAXORDERQUANTITY,
        GetItemsResource.RENTALOFFERS_LISTINGS_AVAILABILITY_MESSAGE,
        GetItemsResource.RENTALOFFERS_LISTINGS_AVAILABILITY_MINORDERQUANTITY,
        GetItemsResource.RENTALOFFERS_LISTINGS_AVAILABILITY_TYPE,
        GetItemsResource.RENTALOFFERS_LISTINGS_BASEPRICE,
        GetItemsResource.RENTALOFFERS_LISTINGS_CONDITION,
        GetItemsResource.RENTALOFFERS_LISTINGS_CONDITION_SUBCONDITION,
        GetItemsResource.RENTALOFFERS_LISTINGS_DELIVERYINFO_ISAMAZONFULFILLED,
        GetItemsResource.RENTALOFFERS_LISTINGS_DELIVERYINFO_ISFREESHIPPINGELIGIBLE,
        GetItemsResource.RENTALOFFERS_LISTINGS_DELIVERYINFO_ISPRIMEELIGIBLE,
        GetItemsResource.RENTALOFFERS_LISTINGS_DELIVERYINFO_SHIPPINGCHARGES,
        GetItemsResource.RENTALOFFERS_LISTINGS_MERCHANTINFO,
    ]

    try:
        get_items_request = GetItemsRequest(
            partner_tag=partner_tag,
            partner_type=PartnerType.ASSOCIATES,
            marketplace="www.amazon.it",
            condition=Condition.NEW,
            item_ids=item_ids,
            resources=get_items_resource,
        )
    except ValueError as exception:
        print("Error in forming GetItemsRequest: ", exception)
        return

    try:

        response = default_api.get_items(get_items_request)

        print("API called Successfully")
        # print("Complete Response:", response)
        return response

        if response.errors is not None:
            print("\nPrinting Errors:\nPrinting First Error Object from list of Errors")
            print("Error code", response.errors[0].code)
            print("Error message", response.errors[0].message)

    except ApiException as exception:
        print("Error calling PA-API 5.0!")
        print("Status code:", exception.status)
        print("Errors :", exception.body)
        print("Request ID:", exception.headers["x-amzn-RequestId"])

    except TypeError as exception:
        print("TypeError :", exception)

    except ValueError as exception:
        print("ValueError :", exception)

    except Exception as exception:
        print("Exception :", exception)