Skip to content

Instantly share code, notes, and snippets.

@totherme
Last active December 30, 2019 15:57
Show Gist options
  • Save totherme/e29fef426cb487261cf7910bd261ab2d to your computer and use it in GitHub Desktop.
Save totherme/e29fef426cb487261cf7910bd261ab2d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
CURL="${CURL_COMMAND:-curl -sS}"
main() {
local bar_url
check_our_dependencies
for bar_url in $(handlebar_urls) ; do
if $CURL "$bar_url" | has_size_38cm ; then
echo "$bar_url"
fi
done
}
check_our_dependencies() {
for prog in curl cut jq ; do
if ! command -v "$prog" > /dev/null ; then
fail "We need $prog installed for this to work"
fi
done
}
handlebar_urls() {
get_all_bars | filter_product_links
}
has_size_38cm() {
has_size "38cm"
}
has_size() {
size="${1:?Expected a size to check}"
grep 'window\.universal_variable\.product = ' \
| cut -d= -f2- \
| jq -e "$(printf '.skus[].size | select(. == "%s")' "$size")" > /dev/null
}
get_all_bars() {
$CURL "https://www.wiggle.co.uk/cycle/drop-handlebars/?ris=1&o=2"
$CURL "https://www.wiggle.co.uk/cycle/drop-handlebars/?o=2&g=49"
$CURL "https://www.wiggle.co.uk/cycle/drop-handlebars/?o=2&g=97"
}
filter_product_links() {
grep "<a class=\"bem-product-thumb__name" \
| cut -d= -f3 | cut -d\" -f2
}
fail() {
echo "${@}" >&2
}
main "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment