-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_python.py
50 lines (46 loc) · 1.24 KB
/
api_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import request
from flask import make_response,jsonify
from get_address_details import main_extract
def send_response(data,code):
response=make_response(
jsonify(
data
),
code,
)
response.headers['Content-Type']="application/json"
return response
def send_response_xml(data,code):
response=make_response(data,code)
response.headers['Content-Type']="application/xml"
return response
def get_address_main_extract():
try:
if 'address' not in request.json or not request.json['address']:
if 'output_format' not in request.json or not request.json['output_format']:
return send_response({
"status" : False,
"Message" : "address and format not mentioned in request",
"Data" : {}
},400)
address=request.json['address']
output_format=request.json['output_format']
if(output_format=="xml"):
data=main_extract(address,output_format)
if data:
return send_response_xml(data,400)
else:
data=main_extract(address,output_format)
if data:
return send_response({
"status" : True,
"Message" : "Successfull",
"Data" : data
},400)
except Exception as e:
print(e)
return send_response({
"status" : False,
"Message" : "Failed",
"Data" : {}
},500)