def check_raspberryPi(): repository.set_dbc(repository.DBC()) logging.debug("Checking alerts") for userConfiguration in repository.get_dbc().get_table( 'UserConfiguration').all(): user_id = userConfiguration['user_id'] repository.get_dbc().insert_user_configuration(user_id) cpu_percentage = get_cpu_percentage() temp_degrees = get_temp_info() # 40 -> For testing purposes ram_percentage = get_ram_info().percent disk_percentage = get_disk_info().percent if repository.get_dbc().get_cpu_alert(user_id) != None and int( repository.get_dbc().get_cpu_alert(user_id)) <= cpu_percentage: print(cpu_percentage) print("CPU PERCENTAGE IS HIGH") if repository.get_dbc().get_temp_alert(user_id) != None and int( repository.get_dbc().get_temp_alert(user_id)) <= temp_degrees: print(temp_degrees) print("TEMP IS HIGH") if repository.get_dbc().get_ram_alert(user_id) != None and int( repository.get_dbc().get_ram_alert(user_id)) <= ram_percentage: print(ram_percentage) print("RAM USAGE IS HIGH") if repository.get_dbc().get_disk_alert(user_id) != None and int( repository.get_dbc().get_disk_alert( user_id)) <= disk_percentage: print(disk_percentage) print("DISK USAGE IS HIGH")
def init(config_path, token, db_path, refresh_chollos, log_level, log_path): set_config(Config()) if config_path: get_config().load_config_file(config_path) get_config().load_config_variables(token, db_path, refresh_chollos, log_level, log_path) # ================== Initializer ================== set_dbc(DBC(path=get_config().db_path)) init_scheduler() # ============== LOGs ============ log_formatter = logging.Formatter( fmt= '[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', datefmt='%d-%m-%y %H:%M:%S') logger = logging.getLogger() if get_config().log_path is not None: fileHandler = RotatingFileHandler(get_config().log_path, mode='a', maxBytes=5 * 1024 * 1024, backupCount=2, encoding='utf-8', delay=0) fileHandler.setFormatter(log_formatter) logger.addHandler(fileHandler) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(log_formatter) logger.addHandler(consoleHandler) logger.setLevel(get_config().log_level) logging.getLogger('telegram').setLevel(logging.INFO) # ================== BOT ================== updater = Updater(get_config().telegram_token) load_dispatcher(updater.dispatcher) set_bot(updater.bot) # Start the Bot updater.start_polling(timeout=15, read_latency=6) logging.info("Bot started") schedule_chollos(get_config().default_refresh_chollos) # Run the bot until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT updater.idle() logging.info("Bye !")
def init(config_path, token, admin_user_id, admin_username, db_path, refresh_inbox, log_level, log_path): set_config(Config()) if config_path: get_config().load_config_file(config_path) get_config().load_config_variables(token, admin_user_id, admin_username, db_path, refresh_inbox, log_level, log_path) # ================== Initializer ================== set_dbc(DBC(path=get_config().db_path)) init_scheduler() # ============== LOGs ============ log_formatter = logging.Formatter( fmt= '[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', datefmt='%d-%m-%y %H:%M:%S') logger = logging.getLogger() if get_config().log_path is not None: fileHandler = logging.FileHandler(get_config().log_path) fileHandler.setFormatter(log_formatter) logger.addHandler(fileHandler) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(log_formatter) logger.addHandler(consoleHandler) logger.setLevel(get_config().log_level) logging.getLogger('telegram').setLevel(logging.INFO) # ================== BOT ================== updater = Updater(get_config().telegram_token) load_dispatcher(updater.dispatcher) set_bot(updater.bot) # Start the Bot updater.start_polling(timeout=15, read_latency=6) logging.error("Bot started") init_email_service() # Run the bot until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT updater.idle() logging.error("Bye !")
def get_user_chollos(user_id): repository.set_dbc(repository.DBC()) keywords = repository.get_dbc().get_keywords(user_id) merchants = repository.get_dbc().get_merchants(user_id) chollos = [] chollos.extend(extraer_datos_pagina_chollometro() + extraer_datos_pagina_michollo()) result = [] # Use "chcp 65001" command on windows console in order to show the string correctly for chollo in chollos: for keyword in keywords: if (keyword == '*' or keyword in chollo.titulo) and ('*' in merchants or chollo.comercio in merchants): # print(chollo.titulo+' - '+chollo.comercio+' - '+chollo.precio+' - '+chollo.descripcion+' - '+chollo.cupon+' - '+chollo.link) result.append(chollo) return result
def get_user_chollos(user_id): repository.set_dbc(repository.DBC()) keywords = repository.get_dbc().get_keywords(user_id) merchants = repository.get_dbc().get_merchants(user_id) price = repository.get_dbc().get_price(user_id) chollos = [] chollos.extend(extraer_datos_pagina_chollometro() + extraer_datos_pagina_michollo()) result = [] # Use "chcp 65001" command on windows console in order to show the string correctly for chollo in chollos: try: precio = float(chollo.precio.replace(',','.').replace('€','')) except ValueError: precio = 0 for keyword in keywords: if ((keyword.strip() == '*' or keyword.strip().lower() in chollo.titulo.lower()) and ('*' in merchants or chollo.comercio.strip() in merchants or not chollo.comercio) and ('*' == price or precio <= float(price.replace(',','.')))): # print(chollo.titulo+' - '+chollo.comercio+' - '+chollo.precio+' - '+chollo.descripcion+' - '+chollo.cupon+' - '+chollo.link) result.append(chollo) return result