Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Last active June 15, 2022 04:05
Show Gist options
  • Save luckylittle/be19caeb6300e5953a834923b6a5b1de to your computer and use it in GitHub Desktop.
Save luckylittle/be19caeb6300e5953a834923b6a5b1de to your computer and use it in GitHub Desktop.
Script returns last three Audible products from a specific publisher
#!/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
#!/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
@luckylittle
Copy link
Author

Also useful:

#!/bin/zsh
source /home/lmaly/Projects/audible-cli/venv/bin/activate
AUDIBLE_PLUGIN_DIR=~/Projects/audible-cli/plugin_cmds/ audible image-urls ${@}
deactivate

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