Last active
August 29, 2015 14:05
-
-
Save blakfeld/da334fd1cc77b713975b to your computer and use it in GitHub Desktop.
Check if Destiny Ghost is in stock on Amazon
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 | |
URL='http://www.amazon.com/Destiny-Ghost-Xbox-One/dp/B00LH6C6VW/ref=sr_1_1?s=videogames&ie=UTF8&qid=1407613552&sr=1-1&keywords=xbox+one+destiny+ghost' | |
USER_AGENT='Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/4.5.2 GTB5' | |
SEARCH_TERM='<span class="availRed">Sign up to be notified when this item becomes available.</span>' | |
EMAIL="name@email.com" | |
PHONE_ADDRESS="1234567890@provider.com" | |
SUCCESS_COUNT=0 | |
send_mail () { | |
ADDRESS=$1 | |
cat << EOF | /usr/bin/osascript | |
tell application "Mail" | |
set newMessage to make new outgoing message with properties {subject: "Ghost Edition is in Stock", content: "Go buy it! $URL", visible:true} | |
tell newMessage | |
make new to recipient at the end of to recipients with properties {address:"$ADDRESS"} | |
send | |
end tell | |
end tell | |
EOF | |
} | |
notifier () { | |
MSG_TITLE=$1 | |
MSG_TEXT=$2 | |
osascript -e "display notification \"$MSG_TEXT\" with title \"$MSG_TITLE\"" | |
} | |
while :; do | |
curl -s -H "user-agent: $USER_AGENT" $URL | grep "$SEARCH_TERM" > /dev/null | |
if [[ $? -ne 0 ]]; then | |
SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
else | |
SUCCESS_COUNT=0 | |
fi | |
# Require 3 consecutive successes to prevent false positives | |
if [[ $SUCCESS_COUNT == 3 ]]; then | |
echo "In Stock!" | |
notifier "Destiny" "Ghost Edition in stock on Amazon!" | |
send_mail $EMAIL | |
send_mail $PHONE_ADDRESS | |
exit 0 | |
fi | |
sleep 30 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment