-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
31 lines (28 loc) · 953 Bytes
/
api.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
from flask import Flask,request,jsonify
from pyswip import Prolog
from flask.ext.cors import CORS, cross_origin
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/', methods=['POST'])
@cross_origin()
def get_result():
pokemon = request.json['pokemon']
prolog = Prolog()
prolog.consult('src/engine.pl')
re_list = list(prolog.query('pokerule:beat(Pokemon,Move,'+pokemon+')'))
poke_list = []
temp = {"Pokemon":"",'Moves':[]}
for i in re_list :
if temp['Pokemon'] != i['Pokemon'] :
temp['Moves'] = list(set(temp['Moves']))
poke_list.append(temp)
temp = {"Pokemon":i['Pokemon'],"Moves":[]}
temp["Moves"].append(i['Move'])
else :
temp["Moves"].append(i['Move'])
temp['Moves'] = list(set(temp['Moves']))
poke_list.append(temp)
return jsonify(poke_list[1:len(poke_list)])
if __name__ == '__main__':
app.run('0.0.0.0',9999)