-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
62 lines (50 loc) · 1.54 KB
/
server.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
#!/usr/bin/env python
from flask import Flask, request, jsonify
from search_functions import google, bing, yahoo
# runs on localhost:5000
app = Flask(__name__)
@app.route('/')
def index():
return "Please refer to /search"
@app.route('/search', methods=['GET'])
def search():
search_query = request.args.get('q')
try:
google_results = google(search_query)
except:
google_results = ["No Results Found"]
try:
yahoo_results = yahoo(search_query)
except:
yahoo_results = ["No Results Found"]
try:
bing_results = bing(search_query)
except:
bing_results = ["No Results Found"]
return jsonify({"results": google_results + yahoo_results + bing_results})
@app.route('/bing/search', methods=['GET'])
def bing_search():
search_query = request.args.get('q')
try:
bing_results = bing(search_query)
except:
bing_results = ["No Results Found"]
return jsonify({"results": bing_results})
@app.route('/google/search', methods=['GET'])
def google_search():
search_query = request.args.get('q')
try:
google_results = google(search_query)
except:
google_results = ["No Results Found"]
return jsonify({"results": google_results})
@app.route('/yahoo/search', methods=['GET'])
def yahoo_search():
search_query = request.args.get('q')
try:
yahoo_results = yahoo(search_query)
except:
yahoo_results = ["No Results Found"]
return jsonify({"results": yahoo_results})
if __name__ == '__main__':
app.run(debug=True)