Example #1
0
def main_program():
    logger.info("Application started")
    UserData.init()
    RUZPython.init()
    BotLogic.start()
    while True:
        BotLogic.update()
        sleep(0.5)
Example #2
0
def get_timetable(email, start, end):
    logger.info("Getting timetable for " + email)
    try:
	    response = requests.get(__base_URL.format(start.strftime(__date_format),
                                                         end.strftime(__date_format),
                                                         email), timeout=3)
    except requests.exceptions.Timeout:
        return None
    if response is None or response.status_code != 200:
        logger.error("RUZ Server doesn't response correctly")
        return None
    logger.info("Got timetable " + email)
    json = response.json()
    try:
        return Lesson.split_days(Lesson(lesson) for lesson in json)
    except:
        log = dumps(json, indent=' '*4, sort_keys=True, ensure_ascii=False)
        logger.error("Got none from RUZ. Got: "+log)
        BotLogic.send_admin_alert(got_wrong_from_ruz+log)
        return None
Example #3
0
    BotLogic.start()
    while True:
        BotLogic.update()
        sleep(0.5)


if __name__ == "__main__":
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    logging.getLogger("telegram.bot").setLevel(logging.WARNING)
    fh = logging.FileHandler('bot.log')
    fh.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    logger.addHandler(fh)
    logger.addHandler(ch)
    while True:
        try:
            main_program()
        except KeyboardInterrupt:
            break
        except:
            trace = traceback.format_exc()
            logger.critical(trace)
            BotLogic.send_admin_alert(alertMsg+trace)
            UserData.destroy()