def main():
settings = get_settings_data(sysargs.settings)
if sysargs.loglevel:
logging.getLogger().setLevel(getattr(logging, sysargs.loglevel.upper(), logging.WARNING))
api_data = get_api_data(settings,sysargs.date)
# the results look like 2015-12-10T15:47:11+00:00
# so we need to convert from UTC to whatever the local time is
utc = parser.parse(api_data['results']['sunrise'])
sunrise_lcl = utc.astimezone(tz.tzlocal())
utc = parser.parse(api_data['results']['sunset'])
sunset_lcl = utc.astimezone(tz.tzlocal())
# this data is also in api_data['results']['day_length']
daylight_hours = (sunset_lcl - sunrise_lcl).total_seconds() / 60 / 60
if daylight_hours < settings['ideal-day']:
light_lcl = sunrise_lcl - timedelta(hours=(settings['ideal-day']-daylight_hours))
light_lcl = light_lcl.strftime("%H:%M:%S%z")
else:
light_lcl = 0
# write it out to a cache file, basically just makes it so we don't have
# to talk to the sunrise API all the time
data = {}
data['date_local'] = sunrise_lcl.strftime("%Y-%m-%d")
data['sunrise_localtime'] = sunrise_lcl.strftime("%H:%M:%S%z")
data['sunset_localtime'] = sunset_lcl.strftime("%H:%M:%S%z")
data['daylight_hours'] = daylight_hours
data['light_on_localtime'] = light_lcl
writeJSONData(settings,data)
评论列表
文章目录