Skip to content

Instantly share code, notes, and snippets.

@jcttrll
Last active September 8, 2017 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcttrll/dfd01f22bf54fea6a647ab1f10e6d46e to your computer and use it in GitHub Desktop.
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
#!/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
@jcttrll
Copy link
Author

jcttrll commented Aug 11, 2017

Example crontab entry:

0 * * * * FROM_EMAIL=no-reply@example.com TO_EMAIL=me@example.com PRODUCT_URL='http://www.dell.com/en-us/shop/accessories/apd/450-aeuo?ref=192_recs_ttl&c=us&l=en&cs=04' TARGET_PRICE=299.99 $HOME/bin/dell-price-watch.sh &>/dev/null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment