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}
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!"})
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']))
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)