-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
98 lines (84 loc) · 3.27 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
import subprocess
from urllib import response
from flask import Flask, render_template, jsonify, request
import threading
import requests
from search_engines import Google, Bing, Aol, Duckduckgo, Ask, Torch, Qwant, Mojeek, Dogpile
host_name = '0.0.0.0'
port = 5000
app = Flask(__name__)
# https: // bulma.io/documentation/overview/start/
@app.route("/")
def index():
# r = requests.get("http://api.punkapi.com/v2/beers/random")
# beerJson = r.json()
# beer = {
# 'name': beerJson[0]['name'],
# 'abv': beerJson[0]['abv'],
# 'desc': beerJson[0]['description'],
# 'foodPair': beerJson[0]['food_pairing'][0]
# }
return render_template('index.html')
@app.route("/video")
def video():
return render_template('video.html')
@app.route("/scraper", methods=['POST', 'GET'])
def scraper():
content_type = request.headers.get('Content-Type')
if (content_type == 'application/json'):
keyword = request.json['q']
browser = request.json['browser']
pages = int(request.json['pages'])
if browser == 'google':
response = Google().search(keyword, pages)
elif browser == 'bing':
response = Bing().search(keyword, pages)
elif browser == 'aol':
response = Aol().search(keyword, pages)
elif browser == 'ask':
response = Ask().search(keyword, pages)
elif browser == 'torch':
response = Torch().search(keyword, pages)
elif browser == 'qwant':
response = Qwant().search(keyword, pages)
elif browser == 'mojeek':
response = Mojeek().search(keyword, pages)
elif browser == 'dogpile':
response = Dogpile().search(keyword, pages)
elif browser == 'duckduckgo':
response = Duckduckgo().search(keyword, pages)
else:
raise ValueError('Unknown browser: %s' % browser)
return render_template('components/_search_results.html',
keyword=keyword,
results=response.results())
else:
keyword = request.args.get('q')
pages = int(request.args.get('pages', 1))
browser = request.args.get('browser')
if browser == 'google':
response = Google().search(keyword, pages)
elif browser == 'bing':
response = Bing().search(keyword, pages)
elif browser == 'aol':
response = Aol().search(keyword, pages)
elif browser == 'ask':
response = Ask().search(keyword, pages)
elif browser == 'torch':
response = Torch().search(keyword, pages)
elif browser == 'qwant':
response = Qwant().search(keyword, pages)
elif browser == 'mojeek':
response = Mojeek().search(keyword, pages)
elif browser == 'dogpile':
response = Dogpile().search(keyword, pages)
elif browser == 'duckduckgo':
response = Duckduckgo().search(keyword, pages)
else:
raise ValueError('Unknown browser: %s' % browser)
return jsonify(response.results()), 201
if __name__ == '__main__':
threading.Thread(
target=lambda: app.run(host=host_name, port=port,
debug=True, use_reloader=False)
).start()