Last active
June 15, 2022 04:05
-
-
Save luckylittle/be19caeb6300e5953a834923b6a5b1de to your computer and use it in GitHub Desktop.
Script returns last three Audible products from a specific publisher
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/zsh | |
source /home/lmaly/Projects/audible-cli/venv/bin/activate | |
read -r -d '' -A LAST_THREE_MANNING_ASIN <<< "$(audible api /1.0/catalog/products -p publisher="Manning Publications" -p products_sort_by=-ReleaseDate -p num_results=3 | jq -r '.products[].asin')" | |
for ASIN in "${LAST_THREE_MANNING_ASIN[@]:0:$((${#LAST_THREE_MANNING_ASIN[@]}-1))}" | |
do | |
audible api -p response_groups=product_desc /1.0/catalog/products/${ASIN} | jq -r '.product.title' | |
done | |
####### | |
## Output will be e.g.: | |
## Machine Learning Bookcamp | |
## GraphQL in Action | |
## Spring in Action, Sixth Edition | |
####### | |
deactivate |
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 | |
#### | |
# /etc/cron.daily/audible-last-5-manning-email-new.sh | |
#### | |
# If started as root, then re-start as user "centos": | |
if [ "$(id -u)" -eq 0 ]; then | |
exec sudo -H -u centos $0 "$@" | |
echo "This is never reached."; | |
fi | |
source /home/centos/audible-cli/venv/bin/activate | |
read -r -d '' first second third fourth fifth <<< "$(/home/centos/.local/bin/audible api /1.0/catalog/products -p publisher="Manning Publications" -p products_sort_by=-ReleaseDate -p num_results=5 | jq -r '.products[].asin')" | |
cat /dev/null > /home/centos/audible-cli/audible-current-5-manning.txt | |
for ASIN in ${first} ${second} ${third} ${fourth} ${fifth} | |
do | |
/home/centos/.local/bin/audible api -p response_groups=product_desc /1.0/catalog/products/${ASIN} | jq -r '.product.title' >> /home/centos/audible-cli/audible-current-5-manning.txt | |
done | |
deactivate | |
if diff /home/centos/audible-cli/audible-current-5-manning.txt /home/centos/audible-cli/audible-last-5-manning.txt; then | |
echo "No new titles added since last time." | |
else | |
DIFFERENCE=$(diff --changed-group-format='%>' --unchanged-group-format='' /home/centos/audible-cli/audible-last-5-manning.txt /home/centos/audible-cli/audible-current-5-manning.txt) | |
echo -e "New titles detected:\n${DIFFERENCE}" | mail -s "Audible has new Manning titles" centos | |
cp -v /home/centos/audible-cli/audible-current-5-manning.txt /home/centos/audible-cli/audible-last-5-manning.txt | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also useful: