From 1f09bf8b2ec48d2d687cf3739fa1cfb54b1bdc97 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 21:15:18 -0700 Subject: [PATCH] Update solarconditions.py --- solarconditions.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/solarconditions.py b/solarconditions.py index 05af913..43f8f39 100644 --- a/solarconditions.py +++ b/solarconditions.py @@ -6,7 +6,6 @@ import requests # pip install requests import xml.dom.minidom from datetime import timedelta from dateutil import tz # pip install python-dateutil -from suntime import Sun, SunTimeException # pip install suntime from datetime import datetime import ephem # pip install pyephem @@ -56,19 +55,20 @@ def drap_xray_conditions(): xray_flux += "error fetching" return xray_flux -def get_sunrise_sunset(lat=0, lon=0): - if lat != 0 and lon != 0: - sun = Sun(lat, lon) - else: - sun = Sun(LATITUDE, LONGITUDE) +# def get_sunrise_sunset(lat=0, lon=0): +# from suntime import Sun, SunTimeException # pip install suntime +# if lat != 0 and lon != 0: +# sun = Sun(lat, lon) +# else: +# sun = Sun(LATITUDE, LONGITUDE) - to_zone = tz.tzlocal() - today_sr = sun.get_sunrise_time(datetime.now()) - today_ss = sun.get_sunset_time(datetime.now()) - if today_ss < today_sr: # if sunset is before sunrise, then it's tomorrow - today_ss = today_ss + timedelta(1) - todaysun = [today_sr.astimezone(to_zone).strftime('%a %d %I:%M'), today_ss.astimezone(to_zone).strftime('%a %d %I:%M')] - return todaysun +# to_zone = tz.tzlocal() +# today_sr = sun.get_sunrise_time(datetime.now()) +# today_ss = sun.get_sunset_time(datetime.now()) +# if today_ss < today_sr: # if sunset is before sunrise, then it's tomorrow +# today_ss = today_ss + timedelta(1) +# todaysun = [today_sr.astimezone(to_zone).strftime('%a %d %I:%M'), today_ss.astimezone(to_zone).strftime('%a %d %I:%M')] +# return todaysun def get_sun(lat=0, lon=0): obs = ephem.Observer() @@ -99,7 +99,7 @@ def get_sun(lat=0, lon=0): sun_table['transit_time'] = obs.next_transit(sun).datetime().strftime('%a %d %I:%M') sun_table['direction'] = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'][round(sun.az / (2 * ephem.pi / 8)) % 8] - sun_data = f"Next Sun Rise:" + sun_table['rise_time'] + " Set:" + sun_table['set_time'] \ + sun_data = f"Next Sun Rise:" + sun_table['rise_time'] + "\nSet:" + sun_table['set_time'] \ + "\nSun Azimuth:" + str(sun_table['azimuth']) + " Altitude:" + str(sun_table['altitude']) + "Heading: " + sun_table['direction'] return sun_data