60 lines
1.3 KiB
Plaintext
60 lines
1.3 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
set -o errexit
|
||
|
|
||
|
main() {
|
||
|
if [[ "${DEBUG}" ]]; then
|
||
|
set -o xtrace
|
||
|
fi
|
||
|
|
||
|
if [[ "${*}" =~ -h|--help|help|wat ]]; then
|
||
|
__usage "${@}"
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
: "${TMPDIR:=/var/tmp}"
|
||
|
|
||
|
local tmpout="${TMPDIR}/find-wherewhen-$(date +%s).tmp"
|
||
|
local calendar_id="${1}"
|
||
|
shift || true
|
||
|
|
||
|
: "${START_TIME:=$(date --date='1 years ago' -Iseconds)}"
|
||
|
: "${END_TIME:=$(date -Iseconds)}"
|
||
|
|
||
|
if [[ ! "${calendar_id}" ]]; then
|
||
|
echo Missing \<calendar id\> positional argument
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [[ ! "${GOOGLE_API_TOKEN}" ]]; then
|
||
|
echo Missing \$GOOGLE_API_TOKEN
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
local url='https://www.googleapis.com/calendar/v3/calendars'
|
||
|
url="${url}/${calendar_id}/events"
|
||
|
local qs="${qs}maxResults=2500&orderBy=startTime&singleEvents=true"
|
||
|
qs="${qs}&timeMax=$(__qsval "${END_TIME}")"
|
||
|
qs="${qs}&timeMin=$(__qsval "${START_TIME}")"
|
||
|
qs="${qs}&fields=items(summary%2Cend%2FdateTime%2Clocation%2Cstart%2FdateTime)"
|
||
|
qs="${qs}&key=${GOOGLE_API_TOKEN}"
|
||
|
|
||
|
echo "GET ${url}?${qs}"
|
||
|
curl -X GET -s "${url}?${qs}" | jq . >"${tmpout}"
|
||
|
echo "${tmpout}"
|
||
|
}
|
||
|
|
||
|
|
||
|
__qsval() {
|
||
|
jq -r '.|@uri' <<<"\"${1}\""
|
||
|
}
|
||
|
|
||
|
__usage() {
|
||
|
cat <<EOF
|
||
|
Usage: $(basename "${0}") <calendar-id> [-s|--start-time|-e|--end-time]
|
||
|
|
||
|
Find where and when in a given time range (default past 1y).
|
||
|
EOF
|
||
|
}
|
||
|
|
||
|
main "${@}"
|