Files
sky-cam/sunrise.py
T
Claude 713c44adb3 Add LATITUDE/LONGITUDE to conf; sunrise.py reads coords from conf
sunrise.py now reads LATITUDE, LONGITUDE, and TIMEZONE from sky-cam.conf
instead of hardcoded values, using the same pathlib-based pattern as
sunrise2mm.py.  sky-cam.conf gains a comprehensive header with manual
systemd setup instructions and a full script map for future reference.

https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
2026-04-19 00:09:58 +00:00

31 lines
834 B
Python

from datetime import datetime
import pathlib
import pytz
from suntime import Sun
# Locate sky-cam.conf next to this script (works regardless of cwd).
_here = pathlib.Path(__file__).resolve().parent
def _read_conf(path):
conf = {}
with open(path) as f:
for line in f:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
k, v = line.split('=', 1)
conf[k.strip()] = v.strip()
return conf
conf = _read_conf(_here / 'sky-cam.conf')
latitude = float(conf['LATITUDE'])
longitude = float(conf['LONGITUDE'])
tz = pytz.timezone(conf['TIMEZONE'])
sun = Sun(latitude, longitude)
now = datetime.now(tz)
sunrise_utc = sun.get_sunrise_time(now)
sunrise_time = sunrise_utc.astimezone(tz)
print(sunrise_time.strftime('%Y-%m-%d %H:%M:%S'))