当前位置: 首页>>代码示例>>Python>>正文


Python Astral.sun方法代码示例

本文整理汇总了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)
开发者ID:dgeordgy21,项目名称:rpi_wordclock,代码行数:60,代码来源:plugin.py

示例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
开发者ID:danallan,项目名称:shue-server,代码行数:14,代码来源:home.py

示例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
开发者ID:plotaBot,项目名称:rpi_wordclock,代码行数:53,代码来源:plugin.py

示例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
开发者ID:prigarimalla,项目名称:piLight,代码行数:39,代码来源:SunEventGenerator.py

示例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})
开发者ID:flybywire,项目名称:HouseAgent-Astral,代码行数:41,代码来源:haAstral.py


注:本文中的astral.Astral.sun方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。