示例#1
0
def store_graph(scene):
    mongo = Mongo(scene + '_test')
    mongo_automata = automata.Mongo_automata('127.0.0.1', 'automata_test')
    data = ''
    for line in bottle.request.body.readlines():
        if type(line) == bytes:
            line = line.decode('utf8')
        data += line
    if data == '':
        return {'result': 'data null'}
    try:
        data = json.loads(data)
    except:
        traceback.print_exc()
        return {'result': 'data format error : not json'}
    if type(data) != dict:
        return {'result': 'data format error : not dict'}
    try:
        if not mongo_automata.insert_graph_config(data['config']):
            return {'result': 'update config error'}
        if not mongo.store('instruction', data['instruction']):
            return {'result': 'update instruction error'}
        if not mongo.store('automata', data['automata']):
            return {'result': 'update automata error'}
    except:
        traceback.print_exc()
        return {'result': 'error'}
    return {'result': 'ok'}
示例#2
0
def store_data(db, collection, query):
    mongo = Mongo(db)
    data = ''
    for line in bottle.request.body.readlines():
        if type(line) == bytes:
            line = line.decode('utf8')
        data += line
    if data == '':
        return {'result':'data null'}
    try:
        data = json.loads(data)
    except Exception:
        return {'result':'data format error'}
    if type(data) != dict:
        return {'result':'data format error'}
    if collection == 'dialogue':
        result = mongo.store_dialogue(data)
    else:
        result = mongo.store(collection, data)
    if not result:
        return {'result':'error'}
    return {'result':'ok'}