예제 #1
0
def run():
  parser = argparse.ArgumentParser()
  parser.add_argument("--hostname", help="hostname to restore")
  args = parser.parse_args()
  
  hostname = args.hostname
  if hostname and hostname in DATABASES.keys():
    __run(hostname)
  else : 
    logger.error("Please specify a valide database hostname")
def load_corpus(path):
    try:
        with open(path, encoding="utf-8", mode="r+") as f:
            text = ""
            for line in f.readlines():
                text += line.strip()
                text += "\n"
            return text
    except:
        logger.error("Text file not found in corpus")
        exit
예제 #3
0
def process2():
    logger.info('Starting process2')

    if request.args.get('notawaiting') == '1':
        logger.error('Got "notawaiting=1" parameter')
        logger.info('Closing process2\n')
        return False

    logger.info('Doing complicated calculations for process2')
    logger.info('Completed process2')
    return True
def load_stopwords(path):
    try:
        with open(path, encoding="utf-8", mode="r+") as f:
            logger.info("\nLoading stopword list...\n")
            stopwords = []
            for line in f.readlines():
                stopwords.append(line.strip())
            return stopwords

    except:
        logger.error("Stop word list not found in assets")
        return []
예제 #5
0
    def connect(self):
        if not REDIS_URL:
            logger.info('No brain on this bot.')
            return

        logger.info('Brain Connecting...')
        try:
            pool = redis.ConnectionPool(
                host=REDIS_URL, port=REDIS_PORT,
                max_connections=MAX_CONNECTION, db=0
            )
            self.redis = redis.Redis(connection_pool=pool)
            self.redis.set('foo', 'bar')
            logger.info('Brain Connected: {}'.format(REDIS_URL))
        except Exception as e:
            logger.error(traceback.format_exc())
            raise e
예제 #6
0
 def get(self):
     try:
         limit = int(request.args.get('limit', -1))
         offset = int(request.args.get('offset', -1))
         if limit < 0:
             limit = config.DEFAULT_COUNT_MESSAGES
         if offset < 0:
             offset = 0
     except Exception as e:
         logger.error(e)
         raise APIException('wrong arguments')
     messages = ChatMessage.select()\
                    .where(ChatMessage.chat == None)\
                    .order_by(-ChatMessage.date_created)\
                    .offset(offset)\
                    .limit(limit)
     return {
         'messages': [MessageSerializer(m).calc() for m in messages],
     }
예제 #7
0
def query(path):
    try:
        # we want to log a timestamp when request was received. Using logger auto timestamp for that
        logger.info(f'{request.method} - /{path} - {dict(request.args)}')

        if request.method != 'GET':
            logger.error(f'{request.method} method not allowed\n')
            return

        if request.args.get('invalid') == '1':
            logger.error('Got "invalid = 1" parameter\n')
            return

        if path not in ['api/', 'api']:
            logger.error('Invalid path\n')
            return

        process1()

        is_success = process2()
        if not is_success: return

        process3()
    finally:
        return make_response()