Skip to content

Instantly share code, notes, and snippets.

@alexshpilkin
Last active March 31, 2019 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexshpilkin/075d8b6dcfa8f340f3d4d39b1807eade to your computer and use it in GitHub Desktop.
Save alexshpilkin/075d8b6dcfa8f340f3d4d39b1807eade to your computer and use it in GitHub Desktop.
Watch the Ukrainian CVK website and send push notifications
#!/bin/sh -eu
ENDPOINT="https://middleman.ferdinand-muetsch.de/api/messages"
if [ "$#" -ne 2 ]; then
echo "usage: $0 TOKEN ORIGIN" >&2
exit 1
fi
jq -ac --unbuffered --arg token "$1" --arg origin "$2" \
'{"recipient_token": $token, "text": ., "origin": $origin}' | \
while read -r json; do
curl -sSL -X POST -H 'Content-Type: application/json' -d "$json" -- "$ENDPOINT"
done
#!/bin/sh -eu
"$(dirname "$0")/watchcvk" "$2" ${3-} | \
jq -c --unbuffered --arg url "$2" \
'"Data at \($url) changed:\n\n```html\n\(.)```"' | \
push "$1" PushCVK
#!/bin/sh -eu
set -o pipefail
prev=; data=
trap 'rm -f "$prev" "$data"' EXIT
prev=$(mktemp); data=$(mktemp)
touch -- "$prev"
while true; do
curl -sSL -- "$1" | iconv -f cp1251 | \
hq 'main > *:not(.noprint)' data >"$data"
if diff -q "$prev" "$data" >/dev/null; then :; else
jq -Rsc --unbuffered . <"$data"
mv "$data" "$prev"
fi
sleep "${2-60}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment