示例#1
0
文件: praytime.py 项目: grimpy/pyazan
 def __init__(self, location, alert_on):
     self.praytime = Praytime(location)
     self.waitingfor = getNextPrayer(self.praytime)
     prayername = getPreviousPrayerName(self.waitingfor[0])
     self.now = (prayername, getattr(self.praytime, prayername))
     self.running = False
     self.alarm = Alarm()
     self._ontime = Event()
     self.alert_on = alert_on
示例#2
0
文件: praytime.py 项目: grimpy/pyazan
class PrayerTimesNotifier(object):
    def __init__(self, location, alert_on):
        self.praytime = Praytime(location)
        self.waitingfor = getNextPrayer(self.praytime)
        prayername = getPreviousPrayerName(self.waitingfor[0])
        self.now = (prayername, getattr(self.praytime, prayername))
        self.running = False
        self.alarm = Alarm()
        self._ontime = Event()
        self.alert_on = alert_on

    @property
    def onTime(self):
        return self._ontime

    def start(self):
        """
        Start notifying on prayers times
        """
        if self.waitingfor == self.now or not self.running:
            self.waitingfor = getNextPrayer(self.praytime, self.now[0])
            logging.info("Adding alarm %s", self.waitingfor)
            self.alarm.addAlarm(self.waitingfor[1], self._notify, self.waitingfor[0], self.waitingfor[1])
        self.running = True
        return True

    def _notify(self, *args):
        self.now = self.waitingfor
        if self.waitingfor[0] in self.alert_on:
            self._ontime.fire(*args)
        self.start()

    def __str__(self):
        return str(self.praytime)

    def __repr__(self):
        return str(self)