예제 #1
0
        return delta.total_seconds()

    def _get_next_alarm(self):
        today = datetime.now()
        today_alarm = datetime(today.year, today.month, today.day, 18, 40, 0)
        if (today_alarm - today - timedelta(seconds=15)).days >= 0:
            return today_alarm
        else:
            return today_alarm + timedelta(days=1)

    def run(self):
        if self.chat_client.connect():
            self.chat_client.process(block=False)
            while True:
                sleep(self._get_secs_to(self._get_next_alarm()))
                self.send_alarm()
        else:
            raise RuntimeError("Unable to connect!")


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO,
                        format='%(levelname)-8s %(message)s',
                        stream=sys.stdout)
    oauth = OAuth()
    oauth.read_cfg('oauth.cfg')
    jid = '*****@*****.**'
    chat_client = ChatClient(jid, oauth)
    medbot = MedBot(chat_client, 'Buddy')
    medbot.run()
예제 #2
0
        return delta.total_seconds()

    def _get_next_alarm(self):
        today = datetime.now()
        today_alarm = datetime(today.year, today.month, today.day, 18, 40, 0)
        if (today_alarm - today - timedelta(seconds=15)).days >= 0:
            return today_alarm
        else:
            return today_alarm + timedelta(days=1)

    def run(self):
        if self.chat_client.connect():
            self.chat_client.process(block=False)
            while True:
                sleep(self._get_secs_to(self._get_next_alarm()))
                self.send_alarm()
        else:
            raise RuntimeError("Unable to connect!")


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO,
                        format='%(levelname)-8s %(message)s',
                        stream=sys.stdout)
    oauth = OAuth()
    oauth.read_cfg('oauth.cfg')
    jid = '*****@*****.**'
    chat_client = ChatClient(jid, oauth)
    medbot = MedBot(chat_client, 'Buddy')
    medbot.run()