def backup(self):
     now = DateHandler.get_datetime_now()
     last_backup = self.get_value_name_key('backup', 'last_backup')
     last_backup = DateHandler.parse_datetime(last_backup)
     date_last_backup = DateHandler.date(last_backup)
     hour_last_backup = DateHandler.time(last_backup)
     if date_last_backup < DateHandler.date(now):
         if hour_last_backup <= DateHandler.time(now):
             mapping = {'last_backup': str(now)}
             self.set_name_key('backup', mapping=mapping)
             self.redis.save()
             return True
     else:
         return False
Esempio n. 2
0
def admin(_, update):
    """
    Send admin commands
    """
    chat_id = update.chat.id
    if str(chat_id) not in db.list_admins():
        return
    update.reply_text(text=admin_text, quote=False, parse_mode='html')


# Start Bot
if __name__ == "__main__":
    try:
        logger.critical('Press Ctrl+%s to exit' % 'C')
        print('Press Ctrl+{0} to exit'.format('C'))
        scheduler = AsyncIOScheduler()
        last_date = DateHandler.get_datetime_now() + timedelta(days=-1)
        start_date = DateHandler.combine(last_date.date(),
                                         DateHandler.time('06:00:00-03:00'))
        scheduler.add_job(daily_liturgy,
                          "interval",
                          days=1,
                          start_date=start_date)
        scheduler.start()
        bot.run()

    except RPCError as _:
        error(_)
        logger.critical(f'{_}')
        print(_)