Last active
June 9, 2019 14:31
-
-
Save sillypears/f235800738456a5897b5a0631f34896f to your computer and use it in GitHub Desktop.
Nintendo eShop Website Change Tracker
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 | |
################### | |
# GLOBAL VARS # | |
################### | |
l_user="$1" | |
name="$2" | |
p_name="$3" | |
eshop_link="$4" | |
nsid="$5" | |
folder="/var/tmp/${name}" | |
n_page="${name}_page.html" | |
o_page="${name}_page_old.html" | |
n_path="${folder}/${n_page}" | |
o_path="${folder}/${o_page}" | |
subject="${p_name} Webpage Changes" | |
emails="$6" | |
purchase_link="https://ec.nintendo.com/title_purchase_confirm?title=${nsid}" | |
domain="<you pick :)>" | |
#################### | |
# FUNCTIONS # | |
#################### | |
print_usage() { | |
echo "Usage:" | |
echo "$0 <local_user> <game_name> <pretty_game_name> <eshop_link> <nsid> <comma_separated_emails>" | |
echo "" | |
echo "Example:" | |
echo "$0 \"poop\" \"abc\" \"AbC\" \"https://www.nintendo.com/games/detail/<game or whatever>/\" \"700100000XXXXX\" \"my@email.com\" " | |
} | |
#################### | |
# MAIN # | |
#################### | |
if (( $# != 6 )) | |
then | |
print_usage | |
exit 6 | |
fi | |
# Create folder if it doesn't exist | |
if [ ! -d ${folder} ] | |
then | |
mkdir -p ${folder} | |
fi | |
# Move the last page check | |
if [ -s ${n_path} ] | |
then | |
mv ${n_path} ${o_path} | |
fi | |
# Pull the new page | |
curl "${eshop_link}" > ${n_path} 2>/dev/null | |
# Verify that the old page exists again | |
if [ -s ${o_path} ] | |
then | |
# Change the rights to the files because why not | |
chmod 777 ${o_path} | |
chmod 777 ${n_path} | |
chown ${l_user}:${l_user} ${o_path} ${n_path} | |
# See if there are any new changes | |
status=$(sdiff -s ${o_path} ${n_path}) | |
#status="a" # This line is to test emails, uncomment to force an email | |
# If we have any changes, send some stuff! | |
if [ -n "${status}" ] | |
then | |
echo "Changed detected" | |
echo "OLD | NEW" | |
echo ${status} | |
mail -r "${name}-page-changes@${domain}" -s "${subject}" ${emails} < <(echo -e "OLD | NEW "; echo ${status}; echo "${purchase_link}") | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment