Skip to content

Instantly share code, notes, and snippets.

@pingiun
Last active July 20, 2020 14:54
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 pingiun/a16745332ea0fc4bc80bb2648fd489e9 to your computer and use it in GitHub Desktop.
Save pingiun/a16745332ea0fc4bc80bb2648fd489e9 to your computer and use it in GitHub Desktop.
Generate newsletter introduction piece, license: GPL-3.0
#!/usr/bin/env bash
set -euo pipefail
get_events() {
lang_website=$1
export LC_ALL=$2
for pk in $(curl -H "Accept-Language: $lang_website" "https://thalia.nu/api/v1/events/" 2>/dev/null | jq '.|=sort_by(.start)|.[].pk'); do
event=$(curl -H "Accept-Language: $lang_website" "https://thalia.nu/api/v1/events/$pk/" 2>/dev/null)
title=$(jq --raw-output '.title' <<<"$event")
reg_start=$(jq --raw-output '.registration_start' <<<"$event")
if [ "${reg_start}" = "null" ]; then
continue
fi
now=$(date '+%Y-%m-%dT%H:%M:%S+02:00')
oneweek=$(date -v +1w -v +1d '+%Y-%m-%dT%H:%M:%S+02:00')
if [[ "${reg_start}" < "${now}" ]]; then
>&2 echo "Registrations for ${title} have already opened"
continue
fi
if [[ "${reg_start}" > "${oneweek}" ]]; then
>&2 echo "Registrations for ${title} will not open soon"
continue
fi
presentdate=$(date -j -f '%Y-%m-%dT%H:%M:%S+02:00' "${reg_start}" "+%A %H:%M")
echo "<p>- <a href=\"https://thalia.nu/events/$pk/\">${title}</a> (${presentdate})</p>"
done
}
echo "<p>This week the following registrations will open:</p>"
get_events "en" "en_US.UTF-8"
echo "<p>Kind regards,</p>"
echo "<p>Jelle Besseling<br><em>Secretary of the 29th board of study association Thalia, 2019-2020</em></p>"
echo
echo "<p>Deze week zullen de registraties van de volgende evenementen openen:"
get_events "nl" "nl_NL.UTF-8"
echo "<p>Groetjes,</p>"
echo "<p>Jelle Besseling<br><em>Secretaris van het 29e bestuur der studievereniging Thalia, 2019-2020</em></p>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment