-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
36 lines (26 loc) · 1.03 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
from flask import Flask, jsonify, json
from flask_restful import Resource, Api, reqparse
from searchers import Searcher
import requests
app = Flask(__name__)
api = Api(app)
class RetrievalAPI(Resource):
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('q', type=str)
'''url = 'http://npmsearch.com/query?q='+parser.parse_args().get('q') +\
'&size=200&fields=name,keywords,description,readme'''
q = parser.parse_args().get('q')
# n = '20'
searcher = Searcher()
print('Running metasearch')
ranking, result = searcher.metasearch(q, 'javascript package')
'''df = pd.read_json(json_string, encoding="utf-8")
df = df.iloc[0:20, :]
result = df["results"].to_json(orient='records')
result = {"total": str(len(df)), "results": json.loads(result)}'''
print(ranking)
return jsonify(result)
api.add_resource(RetrievalAPI, '/retrieval', endpoint='retrieval')
if __name__ == '__main__':
app.run(debug=True)