Created
April 24, 2022 17:53
-
-
Save souravs17031999/b7d9ea1be4c9f756084fbe7f457406e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def trigger_amazon_product_price_notifications(): | |
print( | |
"*********************** CRON for sending notifications for AMAZON Offers deal of the day ********************" | |
) | |
datetime_NY = datetime.datetime.now(tz_AK) | |
print("[CRON TIME (IST)]: ", datetime_NY.strftime("%A, %d %B %Y %I:%M%p")) | |
print("[CRON TIME (UTC)]: ", datetime.datetime.utcnow()) | |
try: | |
json_product_response = get_amazon_product_response() | |
send_notify = False | |
current_price_of_product = json_product_response["product"]["buybox_winner"]["rrp"]["value"] | |
if json_product_response["product"]["buybox_winner"]["save"] is not None: | |
current_price_of_product -= json_product_response["product"]["buybox_winner"]["save"]["value"] | |
print(f"[AMAZON]: Found product price for product ID {AMAZON_PRODUCT_ID_ASIN}: {current_price_of_product}") | |
if int(AMAZON_PRODUCT_TRIGGER_PRICE_LIMIT_INR[0]) <= current_price_of_product < int(AMAZON_PRODUCT_TRIGGER_PRICE_LIMIT_INR[1]): | |
send_notify = True | |
if send_notify: | |
print("Yeay ! Found Product within range specified. Requesting Twilio to send SMS....") | |
message_body = get_message_for_twilio_SMS(json_product_response, current_price_of_product) | |
send_twilio_notifications(message_body) | |
else: | |
print("Missed for this CRON attempt ! Current price was beyond your budget.") | |
except Exception as e: | |
print(f"[ERROR]: {e}") | |
print( | |
"status: failure, message: Cron service failed to execute Job !!!" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment