示例#1
0
def sendJSON():
    global recentUpload
    if request.method == 'POST':
        jsonObj = request.get_json(False,False,False)

        print("JSON RECEIVED")

        util.changeAllKeys(jsonObj, u'cellGroups', u'groups')
        util.changeAllKeys(jsonObj, u'cellAliases', u'neuron_aliases')
        util.changeAllKeys(jsonObj, u'name', u'entity_name')
        util.changeAllKeys(jsonObj, u'type', u'entity_type')

        print(json.dumps(jsonObj, indent=4))

        recentUpload = recentUpload.replace(app.config['UPLOAD_FOLDER'] + '/', 'exports/')
        print('Export File: %s' % recentUpload)
        with open(recentUpload, 'w') as fout:
            json.dump(jsonObj, fout, indent=4)

        return jsonify({"success" : True})

    elif request.method == 'GET':
        try:
            print("using file: %s" % recentUpload)
            with open(recentUpload) as fin:
                jsonObj = json.load(fin)

            print("JSON SENT")
            print(jsonObj)
            return jsonify(jsonObj)

        except IOError:
            print("SERVER ERROR: No JSON file to upload!")

    return jsonify({"success" : False})
示例#2
0
def saveJSONFile(fileName, JSON):
    util.changeAllKeys(JSON, u'cellGroups', u'groups')
    util.changeAllKeys(JSON, u'cellAliases', u'neuron_aliases')
    util.changeAllKeys(JSON, u'name', u'entity_name')
    util.changeAllKeys(JSON, u'type', u'entity_type')

    with open(fileName, 'w') as fout:
        json.dump(JSON, fout, indent=4)
示例#3
0
def saveJSONFile(fileName, JSON):
    util.changeAllKeys(JSON, u'cellGroups', u'groups')
    util.changeAllKeys(JSON, u'cellAliases', u'neuron_aliases')
    util.changeAllKeys(JSON, u'name', u'entity_name')
    util.changeAllKeys(JSON, u'type', u'entity_type')

    with open(fileName, 'w') as fout:
        json.dump(JSON, fout, indent=4)
示例#4
0
def loadJSONFile(fileName):
    try:
        with open(fileName) as fin:
            jsonObj = json.load(fin)

    except IOError:
        print("Error: %s not found." % (fileName, ))
        return {'success': False}

    util.changeAllKeys(jsonObj, u'groups', u'cellGroups')
    util.changeAllKeys(jsonObj, u'neuron_aliases', u'cellAliases')
    util.changeAllKeys(jsonObj, u'entity_name', u'name')
    util.changeAllKeys(jsonObj, u'entity_type', u'type')

    return jsonObj
示例#5
0
def loadJSONFile(fileName):
    try:
        with open(fileName) as fin:
            jsonObj = json.load(fin)

    except IOError:
        print("Error: %s not found." % (fileName,))
        return {'success': False}

    util.changeAllKeys(jsonObj, u'groups', u'cellGroups')
    util.changeAllKeys(jsonObj, u'neuron_aliases', u'cellAliases')
    util.changeAllKeys(jsonObj, u'entity_name', u'name')
    util.changeAllKeys(jsonObj, u'entity_type', u'type')

    return jsonObj
示例#6
0
def sendJSON():
    global recentUpload
    if request.method == 'POST':
        jsonObj = request.get_json(False, False, False)

        print("JSON RECEIVED")

        util.changeAllKeys(jsonObj, u'cellGroups', u'groups')
        util.changeAllKeys(jsonObj, u'cellAliases', u'neuron_aliases')
        util.changeAllKeys(jsonObj, u'name', u'entity_name')
        util.changeAllKeys(jsonObj, u'type', u'entity_type')

        print(json.dumps(jsonObj, indent=4))

        recentUpload = recentUpload.replace(app.config['UPLOAD_FOLDER'] + '/',
                                            'exports/')
        print('Export File: %s' % recentUpload)
        with open(recentUpload, 'w') as fout:
            json.dump(jsonObj, fout, indent=4)

        return jsonify({"success": True})

    elif request.method == 'GET':
        try:
            print("using file: %s" % recentUpload)
            with open(recentUpload) as fin:
                jsonObj = json.load(fin)

            print("JSON SENT")
            print(jsonObj)
            return jsonify(jsonObj)

        except IOError:
            print("SERVER ERROR: No JSON file to upload!")

    return jsonify({"success": False})