本文整理汇总了Python中astral.Astral.sun方法的典型用法代码示例。如果您正苦于以下问题:Python Astral.sun方法的具体用法?Python Astral.sun怎么用?Python Astral.sun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astral.Astral
的用法示例。
在下文中一共展示了Astral.sun方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sun [as 别名]
class plugin:
'''
A class to display the time of sunrise/sunset
Uses the astral library to retrieve information...
'''
def __init__(self, config):
'''
Initializations for the startup of the weather forecast
'''
# Get plugin name (according to the folder, it is contained in)
self.name = os.path.dirname(__file__).split('/')[-1]
self.astral_at_location = Astral()[config.get('plugin_' + self.name, 'location')]
# Choose language to display sunrise
language = config.get('plugin_time_default', 'language')
if language == 'german':
self.taw = wcp_time_german.time_german()
elif language == 'dutch':
self.taw = wcp_time_dutch.time_dutch()
elif language == 'swiss_german':
self.taw = wcp_swiss_german.time_swiss_german()
else:
print('Could not detect language: ' + language + '.')
print('Choosing default: german')
self.taw = wcp_time_german.time_german()
self.bg_color_index = 0 # default background color: black
self.word_color_index = 2 # default word color: warm white
self.minute_color_index = 2 # default minute color: warm white
def run(self, wcd, wci):
'''
Displaying current time for sunrise/sunset
'''
# Get data of sunrise
sun_data = self.astral_at_location.sun(date=datetime.datetime.now(), local=True)
# Display data of sunrise
wcd.animate(self.name, 'sunrise', invert=True)
wcd.setColorToAll(wcc.colors[self.bg_color_index], includeMinutes=True)
taw_indices = self.taw.get_time(sun_data['sunrise'], withPrefix=False)
wcd.setColorBy1DCoordinates(wcd.strip, taw_indices, wcc.colors[self.word_color_index])
wcd.show()
time.sleep(3)
# Display data of sunset
wcd.animate(self.name, 'sunrise')
wcd.setColorToAll(wcc.colors[self.bg_color_index], includeMinutes=True)
taw_indices = self.taw.get_time(sun_data['sunset'], withPrefix=False)
wcd.setColorBy1DCoordinates(wcd.strip, taw_indices, wcc.colors[self.word_color_index])
wcd.show()
time.sleep(3)
# Display current moon phase
moon_phase = int(self.astral_at_location.moon_phase(datetime.datetime.now()))
for i in range(0, moon_phase):
wcd.showIcon('sunrise', 'moon_'+str(i).zfill(2))
time.sleep(0.1)
time.sleep(3)
示例2: daytime
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sun [as 别名]
def daytime():
"""
Compute whether it is currently daytime based on current location
"""
city = Astral()[CITY]
sundata = city.sun()
sunrise = sundata['sunrise'] + timedelta(minutes=DELTA)
sunset = sundata['sunset'] - timedelta(minutes=DELTA)
now = datetime.now(sunrise.tzinfo)
return sunrise < now < sunset
示例3: __init__
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sun [as 别名]
class plugin:
"""
A class to display the time of sunrise/sunset
Uses the astral library to retrieve information...
"""
def __init__(self, config):
"""
Initializations for the startup of the weather forecast
"""
# Get plugin name (according to the folder, it is contained in)
self.name = os.path.dirname(__file__).split('/')[-1]
self.pretty_name = "Sunrise"
self.description = "Displays the current times of sunrise and sunset."
self.astral_at_location = Astral()[config.get('plugin_' + self.name, 'location')]
self.bg_color_index = 0 # default background color: black
self.word_color_index = 2 # default word color: warm white
self.minute_color_index = 2 # default minute color: warm white
def run(self, wcd, wci):
"""
Displaying current time for sunrise/sunset
"""
# Get data of sunrise
sun_data = self.astral_at_location.sun(date=datetime.datetime.now(), local=True)
# Display data of sunrise
wcd.animate(self.name, 'sunrise', invert=True)
wcd.setColorToAll(wcc.colors[self.bg_color_index], includeMinutes=True)
taw_indices = wcd.taw.get_time(sun_data['sunrise'], purist=True)
wcd.setColorBy1DCoordinates(wcd.strip, taw_indices, wcc.colors[self.word_color_index])
wcd.show()
if wci.waitForExit(3.0):
return
# Display data of sunset
wcd.animate(self.name, 'sunrise')
wcd.setColorToAll(wcc.colors[self.bg_color_index], includeMinutes=True)
taw_indices = wcd.taw.get_time(sun_data['sunset'], purist=True)
wcd.setColorBy1DCoordinates(wcd.strip, taw_indices, wcc.colors[self.word_color_index])
wcd.show()
if wci.waitForExit(3.0):
return
# Display current moon phase
moon_phase = int(self.astral_at_location.moon_phase(datetime.datetime.now()))
for i in range(0, moon_phase):
wcd.showIcon('sunrise', 'moon_' + str(i).zfill(2))
if wci.waitForExit(0.1):
return
if wci.waitForExit(3.0):
return
示例4: SunEventGenerator
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sun [as 别名]
class SunEventGenerator(object):
def __init__(self, city, baseUrl, value, zone=0):
self.city = Astral()[city]
self.url = baseUrl+'/setEvent/'
self.value = value
self.zone = zone
def setSunset(self):
return self._setEvent('sunset')
def setSunrise(self):
return self._setEvent('sunrise')
def _setEvent(self, event):
params = {}
if isinstance(self.value, int):
params['mono'] = self.value
else:
params['red'] = self.value[0]
params['green'] = self.value[1]
params['blue'] = self.value[2]
params['delay'] = self._secondsUntilSunEvent(event)
params['zone'] = self.zone
return requests.get(url=self.url, params=params)
def secondsUntilSunset(self):
return self._secondsUntilSunEvent('sunset')
def secondsUntilSunrise(self):
return self._secondsUntilSunEvent('sunrise')
def _secondsUntilSunEvent(self, event):
now = self.city.tz.localize(datetime.now())
seconds = int(((self.city.sun(date=now, local=True))[event] - now).total_seconds())
if seconds < 0:
seconds = int((self.city.sun(date=now+timedelta(days=1), local=True)[event] - now).total_seconds())
return seconds
示例5: fire_minute
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sun [as 别名]
def fire_minute(self):
city = Astral()[self.config.get("astral", "city")]
sun = city.sun()
self.log.debug(sun)
delta = int(time.time()) - int(time.mktime(sun["sunrise"].timetuple())) + 30
if delta > 0:
self.log.info("Sunrise was {0} minutes ago".format(delta // 60))
else:
self.log.info("Sunrise in {0} minutes".format(-(delta // 60)))
self.pluginapi.value_update("1", {"Sunrise delta": delta // 60})
delta = int(time.time()) - int(time.mktime(sun["sunset"].timetuple())) + 30
if delta > 0:
self.log.info("Sunset was {0} minutes ago".format(delta // 60))
else:
self.log.info("Sunset in {0} minutes".format(-(delta // 60)))
self.pluginapi.value_update("1", {"Sunset delta": delta // 60})
delta = int(time.time()) - int(time.mktime(sun["dawn"].timetuple())) + 30
if delta > 0:
self.log.info("Dawn was {0} minutes ago".format(delta // 60))
else:
self.log.info("Dawn in {0} minutes".format(-(delta // 60)))
self.pluginapi.value_update("1", {"Dawn delta": delta // 60})
delta = int(time.time()) - int(time.mktime(sun["dusk"].timetuple())) + 30
if delta > 0:
self.log.info("Dusk was {0} minutes ago".format(delta // 60))
else:
self.log.info("Dusk in {0} minutes".format(-(delta // 60)))
self.pluginapi.value_update("1", {"Dusk delta": delta // 60})
delta = int(time.time()) - int(time.mktime(sun["noon"].timetuple())) + 30
if delta > 0:
self.log.info("Solar noon was {0} minutes ago".format(delta // 60))
else:
self.log.info("Solar noon in {0} minutes".format(-(delta // 60)))
self.pluginapi.value_update("1", {"Solar noon delta": delta // 60})