-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathapp.py
139 lines (124 loc) · 4.43 KB
/
app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from flask import Flask, request, jsonify
from flask_cors import CORS
import json
app = Flask(__name__)
CORS(app)
with open('data.json') as f:
data = json.load(f)
@app.route('/',methods=["GET","POST"])
def all():
if request.method=="GET":
return jsonify(data)
else:
message="method not allowed"
return jsonify(message=message)
@app.route('/element/atomicnumber',methods=["GET","POST"])
def atomicnumber():
if request.method == "GET":
if 'atomicnumber' in request.args:
atomicnumber = request.args['atomicnumber']
for i in data:
if atomicnumber == str(i['atomicNumber']):
return jsonify(i)
else:
message="does not exists"
return jsonify(message=message)
else:
message="does not exists"
return jsonify(message=message)
else:
message="method not allowed"
return jsonify(message=message)
@app.route('/element/atomicname',methods=["GET","POST"])
def atomicname():
if request.method == "GET":
if 'atomicname' in request.args:
atomicname = str(request.args['atomicname'])
for i in data:
if atomicname.lower() == str(i["name"].lower()):
return jsonify(i)
else:
message="does not exists"
return jsonify(message=message)
else:
message="does not exists"
return jsonify(message=message)
else:
message="method not allowed"
return jsonify(message=message)
@app.route('/element/symbol',methods=["GET","POST"])
def atomicsymbol():
if request.method == "GET":
if 'symbol' in request.args:
symbol = str(request.args['symbol'])
for i in data:
if symbol.lower() == str(i['symbol'].lower()):
return jsonify(i)
else:
message="does not exists"
return jsonify(message=message)
else:
message="does not exists"
return jsonify(message=message)
else:
message="method not allowed"
return jsonify(message=message)
@app.route('/element/groupblock',methods=["GET","POST"])
def atomicgroupblock():
if request.method == "GET":
data1=[]
if 'groupblock' in request.args:
groupblock = str(request.args['groupblock'])
for i in data:
if groupblock.lower() == str(i['groupBlock'].lower()):
data1.append(i)
if data1 == []:
message="does not exists"
return jsonify(message=message)
return jsonify(data1)
else:
message="does not exists"
return jsonify(message=message)
else:
message="method not allowed"
return jsonify(message=message)
@app.route('/element/bondingtype',methods=["GET","POST"])
def atomicbondingtype():
if request.method == "GET":
data1=[]
if 'bondingtype' in request.args:
bondingtype = str(request.args['bondingtype'])
for i in data:
if bondingtype.lower() == str(i['bondingType'].lower()):
data1.append(i)
if data1 == []:
message="does not exists"
return jsonify(message=message)
return jsonify(data1)
else:
message="does not exists"
return jsonify(message=message)
else:
message="method not allowed"
return jsonify(message=message)
@app.route('/element/state',methods=["GET","POST"])
def atomicstate():
if request.method == "GET":
data1=[]
if 'state' in request.args:
state = str(request.args['state'])
for i in data:
if state.lower() == str(i['standardState'].lower()):
data1.append(i)
if data1 == []:
message="does not exists"
return jsonify(message=message)
return jsonify(data1)
else:
message="does not exists"
return jsonify(message=message)
else:
message="method not allowed"
return jsonify(message=message)
if __name__ == '__main__':
app.run(host="0.0.0.0",port=80,debug=True)