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
This commit is contained in:
+18
-35
@@ -1,47 +1,30 @@
|
||||
#from suntime import Sun
|
||||
#from datetime import datetime, timedelta
|
||||
#import pytz
|
||||
|
||||
#latitude = YOUR_LATITUDE
|
||||
#longitude = YOUR_LONGITUDE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#sun = Sun(latitude, longitude)
|
||||
#tz = pytz.timezone(timezone)
|
||||
|
||||
# Get yesterday's date and time
|
||||
#yesterday = datetime.now(tz) - timedelta(days=1)
|
||||
#sunrise_time = sun.get_sunrise_time(yesterday).astimezone(tz)
|
||||
|
||||
# Print the sunrise time
|
||||
#print(sunrise_time.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
|
||||
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
import pathlib
|
||||
import pytz
|
||||
from suntime import Sun
|
||||
|
||||
# Example coordinates (e.g., New York City)
|
||||
latitude = re.dacted
|
||||
longitude = re.dacted
|
||||
# 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
|
||||
|
||||
# Define the timezone
|
||||
tz = pytz.timezone('America/New_York')
|
||||
conf = _read_conf(_here / 'sky-cam.conf')
|
||||
|
||||
latitude = float(conf['LATITUDE'])
|
||||
longitude = float(conf['LONGITUDE'])
|
||||
tz = pytz.timezone(conf['TIMEZONE'])
|
||||
|
||||
# Create a Sun object with the given latitude and longitude
|
||||
sun = Sun(latitude, longitude)
|
||||
|
||||
# Get today's date and time in the desired timezone
|
||||
now = datetime.now(tz)
|
||||
|
||||
# Get today's sunrise time in UTC and convert it to the desired timezone
|
||||
sunrise_utc = sun.get_sunrise_time(now)
|
||||
sunrise_time = sunrise_utc.astimezone(tz)
|
||||
|
||||
# Print the sunrise time in the desired format
|
||||
print(sunrise_time.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
|
||||
Reference in New Issue
Block a user