summaryrefslogtreecommitdiff
path: root/bin/astro-transits
diff options
context:
space:
mode:
Diffstat (limited to 'bin/astro-transits')
-rwxr-xr-xbin/astro-transits75
1 files changed, 75 insertions, 0 deletions
diff --git a/bin/astro-transits b/bin/astro-transits
new file mode 100755
index 0000000..8455050
--- /dev/null
+++ b/bin/astro-transits
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+set -e
+
+# The current sky against a natal chart, with astrolog: an ordered transit
+# table and a biwheel image.
+#
+# ASTRO_LAT, ASTRO_LONG where you are, signed decimal degrees (N and E positive)
+# ASTRO_ZONE your standard (winter) UTC offset in hours west,
+# e.g. 5 for New York, -1 for Berlin
+# ASTRO_NATAL the natal chart, an astrolog chart file
+# (default ~/.local/share/astrology/natal.dat)
+# ASTROLOG astrolog's data directory, holding the Swiss
+# Ephemeris files; without seas_18.se1,
+# Chiron/Ceres/Pallas/Juno/Vesta come out as 0Ari00
+# ASTRO_VIEWER image viewer that stays open until closed (default imv)
+#
+# With --emacs, prints TABLE=path and IMAGE=path instead of showing them.
+
+: "${ASTRO_LAT:?set ASTRO_LAT to your latitude}"
+: "${ASTRO_LONG:?set ASTRO_LONG to your longitude}"
+: "${ASTRO_ZONE:?set ASTRO_ZONE to your standard UTC offset in hours west}"
+NATAL="${ASTRO_NATAL:-$HOME/.local/share/astrology/natal.dat}"
+: "${ASTROLOG:=$HOME/.local/share/astrolog}"
+export ASTROLOG
+[ -f "$NATAL" ] || { echo "astro-transits: no natal chart at $NATAL" >&2; exit 1; }
+
+# astrolog wants coordinates as DD:MMH, not the signed decimal degrees
+# ASTRO_LAT/ASTRO_LONG are stored as.
+to_dms() {
+ awk -v v="$1" -v pos="$2" -v neg="$3" 'BEGIN {
+ h = (v < 0) ? neg : pos
+ v = (v < 0) ? -v : v
+ d = int(v)
+ m = int((v - d) * 60 + 0.5)
+ if (m == 60) { d++; m = 0 }
+ printf "%d:%02d%s", d, m, h
+ }'
+}
+LAT_DMS=$(to_dms "$ASTRO_LAT" N S)
+LONG_DMS=$(to_dms "$ASTRO_LONG" E W)
+
+# ASTRO_ZONE is the standard (winter) UTC offset in hours west; derive
+# whether the current moment is in daylight time by comparing it to
+# the actual local UTC offset right now.
+off=$(date +%z)
+sign=${off:0:1}
+offset_min=$((10#${off:1:2} * 60 + 10#${off:3:2}))
+[ "$sign" = "-" ] && offset_min=$(( -offset_min ))
+standard_min=$(( -ASTRO_ZONE * 60 ))
+if [ "$offset_min" -ne "$standard_min" ]; then DAYLIGHT=1; else DAYLIGHT=0; fi
+
+COMMON_ARGS=(-zl "$LONG_DMS" "$LAT_DMS" -z "$ASTRO_ZONE" -z0 "$DAYLIGHT")
+
+TABLE=$(mktemp --suffix=.txt)
+IMAGE=$(mktemp --suffix=.png)
+
+# --emacs hands back the table/image paths instead of displaying them,
+# so a caller (e.g. Emacs) takes ownership of the files and their
+# cleanup; only clean up here if we fail before handing them off.
+if [ "$1" = "--emacs" ]; then
+ trap 'rm -f "$TABLE" "$IMAGE"' ERR
+else
+ trap 'rm -f "$TABLE" "$IMAGE"' EXIT
+fi
+
+astrolog "${COMMON_ARGS[@]}" -i "$NATAL" -Tn -os "$TABLE" >/dev/null
+astrolog "${COMMON_ARGS[@]}" -y "$NATAL" -X -Xbp -Xo "$IMAGE" >/dev/null
+
+if [ "$1" = "--emacs" ]; then
+ echo "TABLE=$TABLE"
+ echo "IMAGE=$IMAGE"
+else
+ cat "$TABLE"
+ "${ASTRO_VIEWER:-imv}" "$IMAGE"
+fi