Last active
September 8, 2017 19:07
-
-
Save jcttrll/dfd01f22bf54fea6a647ab1f10e6d46e to your computer and use it in GitHub Desktop.
cron script to watch a particular product on Dell.com to go on sale
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
#!/bin/bash -e | |
set -o pipefail | |
json=$(curl -sS --fail "$PRODUCT_URL" | | |
grep -Po 'Dell.Services.DataModel = .*;' | | |
awk '{sub("Dell.Services.DataModel = ", "");sub(";$", "");print}' | | |
jq '.Stacks[0].Stack' | |
) | |
name=$(jq -r '.Title.InnerValue' <<<"$json") | |
partNumber=$(jq -r '.Sku.InnerValue' <<<"$json") | |
price=$(jq -r '.Pricing.DellPrice.InnerValue' <<<"$json") | |
imageUrl=$(jq -r '.ProductImage.ImageUri' <<<"$json") | |
description=$(jq -r '.MarketingBlurb.Description' <<<"$json") | |
if awk -v a="$price" -v b="$TARGET_PRICE" 'BEGIN{if(a<=b)exit 0;exit 1}'; then | |
aws $AWS_OPTIONS ses send-email \ | |
--destination "ToAddresses=$TO_EMAIL" \ | |
--from "Dell Price Watcher <$FROM_EMAIL>" \ | |
--message file://<(cat <<-EOF | |
{ | |
"Subject": { | |
"Data": "Target Price Reached" | |
}, | |
"Body": { | |
"Html": { | |
"Data": "<html><body><h2 style='margin-bottom:0'>$name</h2><p style='font-size:smaller;margin-top:0'>Part Number: $partNumber</p><p style='font-weight:bold;font-size:larger'>Current Price: \$$price</p><img style='border:none;display:block;max-width:250px;max-height:250px' src='$imageUrl'/><p>$description</p></body></html>" | |
} | |
} | |
} | |
EOF | |
) &>/dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example crontab entry: