Example #1
0
    def _tellSunrise(self):
        obs = ephem.Observer()
        obs.lat = self._latitude
        obs.long = self._longitude

        # I have to make sure the signal
        # get's send even if I miss the exact time.
        while not self._stopped:
            obs.date = datetime.datetime.now().replace(
                tzinfo=tz.tzlocal()).astimezone(tz.tzutc())
            prevrise = obs.previous_rising(ephem.Sun()).datetime()

            if self._lastsend is None:
                nextrise = obs.next_rising(ephem.Sun()).datetime()
                now = datetime.datetime.now()
                # We have to determin if we have to send sunrise
                # for today (i.e. if it is still day)
                if nextrise.day == now.day:
                    self._lastsend = datetime.datetime(1970, 1, 1)
                else:
                    # Sunrise has ready passed
                    self._lastsend = now

            if prevrise.day != self._lastsend.day:
                self._sgate.send('sunrise')
                self._lastsend = datetime.datetime.now()

            time.sleep(1)
Example #2
0
    def _notify(self, signal):
        obs = ephem.Observer()
        obs.lat = self._latitude
        obs.long = self._longitude

        obs.date = datetime.datetime.now().replace(
            tzinfo=tz.tzlocal()).astimezone(tz.tzutc())

        if obs.previous_rising(ephem.Sun()) >= \
                obs.previous_setting(ephem.Sun()):
            self._sgate.send(signal)