Esempio n. 1
0
def parseDataFromFile(fileName):
	try:
		file = open(fileName, 'r')
	except:
		return 'Cannot open file %s' % fileName
	description = ''
	try:
		object = json.loads(file.read())
	except (TypeError, ValueError):
		return {'result': [{"result": "badJson"}], 'description': description}

	if not ('test' in object):
		return {'result': [{'result': 'badTest'}], 'description': description}

	if 'description' in object:
		description = object['description']

	object = object['test']
	print ("tese")
	result = list()
	if isinstance(object, list):
		for obj in object:
			print("obj")
			print(obj)
			result.append(json.loads(parse_request(obj)))
	else:
		result.append(parse_request(object))
		return {'result': [r1.read()], 'description': description}

	return {'result': result, 'description': description}
Esempio n. 2
0
def analyses():

    if request.method == 'GET' and 'request' in request.args \
    and request.args['request'] != '':
        try:
            sentence = request.args['request']
            tags = parser.parse_request(sentence)
            analyses = dal.query_analyses(tags)
            return responsify(analyses)
        except Exception as e:
            log.error(e)
            abort(500)

    elif request.method == 'POST' and 'request' in request.json \
    and request.json['request'] != '':
        try:
            sentence = request.json['request']
            tags = parser.parse_request(sentence)
            result = dal.queue_analysis(sentence,tags)
            return responsify(result)
        except Exception as e:
            log.error(e)
            abort(500)

    else:
        return responsify({"status" : "warn","error" : "Empty query!"})
Esempio n. 3
0
def serve_ajax():
	if DEBUG:
		print ("Post query")
		#req = json.loads(request.GET['data'])

#	return parser.parse_request(bottle.request.body.read().decode("utf-8"))
	return parser.parse_request(json.loads(bottle.request.GET['data']))
Esempio n. 4
0
def analyses():

    if request.method == 'GET':
        print request.args
        sentence = request.args['request']
        tags = parser.parse_request(sentence)
        analyses = dal.query_analyses(tags)
        return responsify(analyses)

    if request.method == 'POST':
        try:
            sentence = request.json['request']
            tags = parser.parse_request(sentence)
            result = dal.queue_analysis(sentence,tags)
            return responsify(result)
        except Exception as e:
            log.error(e)
            abort(400)