-
Notifications
You must be signed in to change notification settings - Fork 0
/
savejson.py
49 lines (40 loc) · 1.25 KB
/
savejson.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 Flask, render_template,abort,request
import requests
import json
import ast
app = Flask(__name__)
@app.route("/",methods=["GET"])
def index_page():
return render_template("gmap.html")
@app.route("/test", methods=["GET"])
def test():
return "test"
@app.route("/save", methods=["POST"])
def save():
req = request.get_json()
# req = json.loads(req)
print(req)
tosave = dict()
tosave['admin_id'] = req['admin_id']
tosave['type'] = req['type']
tosave['radius'] = req['radius']
tosave['geof_id'] = req['geof_id']
if req['type'] != "circle":
latitude = []
longitude = []
locations = ast.literal_eval(req['locations'])
locations = list(locations)
# print(locations, type(locations))
for loc in locations:
latitude.append(loc[0])
longitude.append(loc[1])
tosave['latitudes'] = latitude
tosave['longitudes'] = longitude
else:
tosave['latitudes'] = req['latitude']
tosave['longitudes'] = req['longitude']
with open("common_resources/sample.json", "a") as outfile:
outfile.write("\n" + json.dumps(tosave))
return "Saved Succesfully"
if __name__ == "__main__" :
app.run(debug=True)