Gap-night finder
Finds the orphan one and two night holes between bookings over the next 30 days and prints the guest arriving next door, so you can offer the night to someone already coming.
Returns: A table of gap nights with the adjacent reservation and guest contact id.
reservations gap-nights View the script
#!/usr/bin/env bash
# Open gap nights in the next 30 days, biggest hole first.
set -euo pipefail
START=$(date -u +%F)
END=$(date -u -v+30d +%F 2>/dev/null || date -u -d "+30 days" +%F)
sendsquared reservations gap-nights \
--start "$START" --end "$END" \
--timezone America/Chicago \
--min-gap 1 --gap-side departure \
> /tmp/.gapnights.json
TOTAL=$(jq '[.data[]?] | length' /tmp/.gapnights.json)
if [ "$TOTAL" -eq 0 ]; then
echo "no open gap nights between $START and $END"
rm -f /tmp/.gapnights.json; exit 0
fi
# next_gap_date is null when nothing is booked after the stay at all, which is
# a bigger hole than a gap, not a smaller one. Both are worth surfacing.
jq -r '
.data[]
# the API returns the stay and the next booked date; the gap is the span between
| . as $r
| (if $r.next_gap_date == null then 999
else (((($r.next_gap_date | sub("\\.[0-9]+Z$";"Z") | fromdateiso8601)
- ($r.departure_date | sub("\\.[0-9]+Z$";"Z") | fromdateiso8601)) / 86400) | floor)
end) as $gap
| select($gap >= 1)
| [ (if $gap == 999 then "open" else ($gap|tostring) end),
($r.departure_date | split("T")[0]),
(if $r.next_gap_date == null then "nothing booked" else ($r.next_gap_date | split("T")[0]) end),
($r.unit_id // "-"),
($r.contact_id // "-"),
(((($r.contact_first_name // "") + " " + ($r.contact_last_name // "")) | ltrimstr(" ") | rtrimstr(" "))) ]
| @tsv
' /tmp/.gapnights.json \
| sort -rn \
| head -40 \
| awk -F'\t' 'BEGIN{printf "%-5s %-12s %-15s %-10s %-10s %s\n","GAP","FREE FROM","BOOKED AGN","UNIT","CONTACT","GUEST"}
{printf "%-5s %-12s %-15s %-10s %-10s %s\n",$1,$2,$3,$4,$5,$6}'
rm -f /tmp/.gapnights.json curl -O https://sendsquared.com/cli/scripts/gap-night-finder.sh view raw