Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#Format distance travelled
distformat='{0:.1f}'.format((float(dist)+float(diststart)) * 0.000539956803)
distformatfull='{0} NM'.format(distformat)
#Format uptime
uptimemin, uptimesec = divmod(uptime, 60)
uptimehour, uptimemin = divmod(uptimemin, 60)
uptimeday, uptimehour = divmod(uptimehour, 24)
uptimeformatfull="%02d DAYS - %02d HOURS - %02d MINUTES" % (uptimeday, uptimehour, uptimemin)
#Calculate sunset/sunrise
if (gpsfix==1 and astronomy_update==1):
eph_observer=ephem.Observer()
eph_observer.lat=str(gpslatdeg)
eph_observer.long=str(gpslondeg)
eph_sun=ephem.Sun()
eph_sun.compute()
sunrise=ephem.localtime(eph_observer.next_rising(eph_sun))
sunset=ephem.localtime(eph_observer.next_setting(eph_sun))
sunriseformat=sunrise.strftime('%H:%M')
sunsetformat=sunset.strftime('%H:%M')
astronomy_update_lock.acquire()
astronomy_update=0
astronomy_update_lock.release()
if start_output_lcd==0:
start_output_lcd=1
if start_output_conky==0:
start_output_conky=1
if start_output_data==0:
start_output_data=1
if start_alarm_system==0:
start_alarm_system=1
if start_update_databases==0:
start_update_databases=1
def datestr(d):
# The date may be wrong because of time zones. Convert to our timezone.
lt = ephem.localtime(d)
# return lt.strftime("%m/%d/%Y")
return lt.strftime("%Y-%m-%d")
def getNextFullMoonDawn(self):
"""
Return the date and time of the next dawn and dusk of the next fullmoon
@return : the next dawn daytime
"""
self.mycity.date = self._getNextFullMoon()
dawn = ephem.localtime(self.mycity.next_rising(ephem.Moon(), use_center=True))
dusk = ephem.localtime(self.mycity.next_setting(ephem.Moon(), use_center=True))
if dawn>dusk:
dawn=ephem.localtime(self.mycity.previous_rising(ephem.Moon(), use_center=True))
return dawn
def friendlydate(d):
lt = ephem.localtime(d)
return lt.strftime("%b %d")
def next_sun_setting(self, observer=None):
""" Returns a datetime object that points at the next sun setting. """
if observer is None:
observer = self._get_observer()
return ephem.localtime(observer.next_setting(self.sun))
def tolocal(utc): # takes ephem date object and returns localtime string
return parser.parse(str(ephem.localtime(utc))).strftime('%Y-%m-%d %H:%M:%S')
def get_next_dusk(self, mycity, delay, args = None) :
"""
Return the date and time of the dusk
@param city: the city wher calculate the event.
@param delay: the delay (in seconds) to the event.
@param args: an optional argument.
@returns: the next dusk daytime or None
"""
if abs(delay) >= 86400:
return None
today = datetime.datetime.today() - datetime.timedelta(seconds=delay+30)
mycity.date = today
dusk = ephem.localtime(mycity.next_setting(ephem.Sun(), use_center = True))
return dusk + datetime.timedelta(seconds=delay)
def getNextFullMoonDawn(self):
"""
Return the date and time of the next dawn and dusk of the next fullmoon
@return : the next dawn daytime
"""
self.mycity.date = self._getNextFullMoon()
dawn = ephem.localtime(self.mycity.next_rising(ephem.Moon(), use_center=True))
dusk = ephem.localtime(self.mycity.next_setting(ephem.Moon(), use_center=True))
if dawn>dusk:
dawn=ephem.localtime(self.mycity.previous_rising(ephem.Moon(), use_center=True))
return dawn