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
31 lines
834 B
Python
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'))
|