Example #1
0
def token():
    print(request.__dict__)
    ag = UserAgent(request)
    print(ag.__dict__)
    if is_empty(ag.api_token) == False:
        return jsonify({"access_token": ag.api_token}), 200
    password = None
    if request.method == 'POST':
        if request.json is not None:
            password = request.json.get('password')
        else:
            password = request.form.get('password')

    key = check_auth(ag.api_key, ag.username, password)
    if is_empty(key):
        return jsonify({"msg": "Bad username or password"}), 401

    access_token = create_access_token(identity=key,
                                       expires_delta=token_expires())
    ag.set_api_token(access_token)
    # session['SessionUser'] = ag.set_session_user()
    # print(session.get('SessionUser'))

    # Set the JWT cookies in the response
    print(access_token)
    return jsonify({'access_token': access_token}), 200
Example #2
0
 def __json__(self, o, cId, uId):
     for key in self.__mapper__.columns.keys():
         if key in ['items', 'form', 'page_name']:
             continue
         elif key == 'page_id':
             if (is_exist(o, key) == False
                     or is_empty(str(o[key])) == True):
                 id = None
             else:
                 id = o[key]
             setattr(self, key, id)
         elif key == 'page_auth':
             if (is_exist(o, key) == False or is_empty(o[key]) == True):
                 auth = None
             else:
                 auth = o[key]
             setattr(self, key, auth)
         elif key == 'page_id_seq':
             if (is_exist(o, key) == False or is_empty(o[key]) == True):
                 seq = None
             else:
                 seq = o[key]
             setattr(self, key, seq)
         elif is_exist(o, key) == False and key in [
                 'page_flag', 'page_deleted', 'page_layout', 'page_open'
         ]:
             setattr(self, key, 0)
         elif key == 'company_id':
             setattr(self, key, cId)
         elif key == 'updated_id':
             setattr(self, key, uId)
         elif key == 'updated_time':
             setattr(self, key, datetime.datetime.now())
         else:
             setattr(self, key, o[key])
Example #3
0
def get_data_mode(language):
    if is_empty(language):
        return DATA_MODE.ja

    codes = DATA_MODE()
    for key, value in codes.__dict__.items():
        if is_empty(value) or key != language:
            continue
        return value
    return DATA_MODE.ja
Example #4
0
 def __json__(self, o):
     for key in self.__mapper__.columns.keys():
         if key == 'option_id':
             if (is_exist(o, key) == False or is_empty(o[key]) == True):
                 id = None
             else:
                 id = o[key]
             setattr(self, key, id)
         else:
             setattr(self, key, o[key])
Example #5
0
 def __json__(self, o, cId, uId):
     for key in self.__mapper__.columns.keys():
         if key == 'server_id':
             if (is_exist(o, key) == False
                     or is_empty(str(o[key])) == True):
                 id = None
             else:
                 id = o[key]
             setattr(self, key, id)
         elif key == 'page_group_id':
             setattr(self, key, pgId)
         else:
             setattr(self, key, o[key])
Example #6
0
 def __json__(self, o, pId):
     for key in self.__mapper__.columns.keys():
         if key == 'form_id':
             if (is_exist(o, key) == False or is_empty(o[key]) == True):
                 id = None
             else:
                 id = o[key]
             setattr(self, key, id)
         elif key == 'page_id':
             setattr(self, key, pId)
         elif key == 'class_name':
             setattr(self, key, o['className'])
         else:
             setattr(self, key, o[key])
Example #7
0
 def __json__(self, o, fId):
     for key in self.__mapper__.columns.keys():
         if key == 'schema_id':
             if (is_exist(o, key) == False or is_empty(o[key]) == True):
                 id = None
             else:
                 id = o[key]
             setattr(self, key, id)
         elif key == 'form_id':
             setattr(self, key, fId)
         elif key == 'object_type':
             setattr(self, key, o['type'])
         else:
             setattr(self, key, o[key])
Example #8
0
def trainer_databases(bot, language):
    if bot is None or is_empty(language):
        return None

    result = {}
    dir = "chatterbot_corpus.data." + get_data_mode(language)
    try:
        trainer = ChatterBotCorpusTrainer(bot)
        trainer.train(dir)
        result['msg'] = 'Data Trainer Completed !!!'
    except Exception as ex:
        print(str(ex))
        result['msg'] = str(ex)

    return result
Example #9
0
def get_bot(bot_mode, storage_adapter, logic_adapters, database_uri):
    # "Chatterbot"
    # bot = ChatBot(
    #     'Terminal',
    #     storage_adapter='chatterbot.storage.SQLStorageAdapter',
    #     logic_adapters=[
    #         'chatterbot.logic.MathematicalEvaluation',
    #         'chatterbot.logic.TimeLogicAdapter',
    #         'chatterbot.logic.BestMatch'
    #     ],
    #     database_uri='sqlite:///database.db'
    # )
    # bot = ChatBot(
    #     'Terminal',
    #     storage_adapter='chatterbot.storage.MongoDatabaseAdapter',
    #     bot_mode=[
    #         'chatterbot.logic.BestMatch'
    #     ],
    #     database_uri='mongodb://localhost:27017/chatterbot-database'
    # )
    if is_empty(bot_mode):
        return None

    if is_empty(storage_adapter) == False and is_empty(
            logic_adapters) == False and is_empty(database_uri) == False:
        return ChatBot(bot_mode,
                       storage_adapter=storage_adapter,
                       logic_adapters=logic_adapters,
                       database_uri=database_uri)
    elif is_empty(storage_adapter) == False and is_empty(
            logic_adapters) == False:
        return ChatBot(bot_mode,
                       storage_adapter=storage_adapter,
                       logic_adapters=logic_adapters)
    elif is_empty(storage_adapter) == False:
        return ChatBot(bot_mode, storage_adapter=storage_adapter)
    else:
        return None
Example #10
0
def get_mysql_pool(conf):
    if is_empty(conf.pool_name):
        return None
    return mysql.connector.pooling.MySQLConnectionPool(
        pool_name=conf.pool_name, pool_size=conf.pool_size, **conf)