89 lines
2.2 KiB
Bash
Executable File
89 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# script for interfacing with planning center online
|
|
|
|
appid=$(cat "$HOME/.local/share/pco/appid")
|
|
token=$(cat "$HOME/.local/share/pco/token")
|
|
userid=$(cat "$HOME/.local/share/pco/userid")
|
|
|
|
get_blockouts_online () {
|
|
curl -su "$appid:$token" "https://api.planningcenteronline.com/services/v2/people/$userid/blockouts" | \
|
|
jq .data[].attributes.ends_at | \
|
|
awk -F'"|-|T' '
|
|
function y(x) {
|
|
if (x == 1) return "Jan"
|
|
if (x == 2) return "Feb"
|
|
if (x == 3) return "Mar"
|
|
if (x == 4) return "Apr"
|
|
if (x == 5) return "May"
|
|
if (x == 6) return "Jun"
|
|
if (x == 7) return "Jul"
|
|
if (x == 8) return "Aug"
|
|
if (x == 9) return "Sep"
|
|
if (x == 10) return "Oct"
|
|
if (x == 11) return "Nov"
|
|
if (x == 12) return "Dec"
|
|
return "Unk"
|
|
}
|
|
|
|
{print y($3) " " $4 " " $2}' | \
|
|
tr '\n' '|' | \
|
|
sed 's/.\{1\}$//'
|
|
}
|
|
|
|
get_blockouts_local () {
|
|
grep "MSG Blockout date" "$DOTREMINDERS" | \
|
|
awk -F' ' '{print $2 " " $3 " " $4}'
|
|
}
|
|
|
|
get_blockouts () {
|
|
all_dates=$(get_blockouts_online)
|
|
OLDIFS="$IFS"
|
|
IFS="|"
|
|
for i in $all_dates; do
|
|
results=$(grep -c "^REM $i MSG Blockout date" "$DOTREMINDERS")
|
|
[ "$results" -eq 0 ] && \
|
|
printf "REM %s MSG Blockout date\n" "$i" >> "$DOTREMINDERS" && \
|
|
printf "added %s to calendar\n" "$i" || \
|
|
printf "omitted %s from the calendar, it's already there\n" "$i"
|
|
done
|
|
IFS="$OLDIFS"
|
|
}
|
|
|
|
push_blockouts () {
|
|
file=$(mktemp)
|
|
get_blockouts_online | tr '|' '\n' >> "$file"
|
|
local=$(get_blockouts_local)
|
|
|
|
# don't mess with the spacing
|
|
OLDIFS=$IFS
|
|
IFS="
|
|
"
|
|
printf "temp file: %s\n" "$file"
|
|
|
|
for i in $local; do
|
|
count=$(grep -c "^$i$" "$file")
|
|
if [ "$count" -eq 0 ]; then
|
|
printf "push: %s\n" "$i"
|
|
stddate=$(date --date="$i" "+%Y-%m-%dT06:00:00Z")
|
|
curl -X POST -H "Content-Type: application/json" -d "
|
|
{
|
|
\"data\": {
|
|
\"attributes\": {
|
|
\"reason\": \"n/a\",
|
|
\"repeat_frequency\": \"no_repeat\",
|
|
\"starts_at\": \"$stddate\",
|
|
\"ends_at\": \"$stddate\"
|
|
}
|
|
}
|
|
}" -su "$appid:$token" "https://api.planningcenteronline.com/services/v2/people/$userid/blockouts"
|
|
fi
|
|
done
|
|
|
|
IFS=$OLDIFS
|
|
|
|
rm "$file"
|
|
}
|
|
|
|
get_blockouts
|
|
push_blockouts
|