-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (73 loc) · 2.3 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
from flask import Flask, render_template, request
from flask_cors import cross_origin
from flask_socketio import SocketIO, send
from strategy.scraperContext import ScraperContext
import sys, threading
app = Flask(__name__)
# socketio = SocketIO(app)
@app.route('/')
def Index():
return render_template('index.html')
@app.route('/search')
def search():
return render_template('search/search.html')
# def repeatFunction():
# threading.Timer(25, repeatFunction).start() # called every minute
# socketio.emit("message", "Connection")
@cross_origin()
@app.route('/process', methods=['POST'])
def process():
# repeatFunction()
# location = {
# "latitude": 50.1109,
# "longitude": 8.6821,
# "accuracy": 100
# }
file = request.files.get("file")
term = request.form.get('term')
keywords = request.form.get('keywords')
engine = request.form.get('engine')
driver = request.form.get('driver')
ignore = request.form.get('ignore')
alexa_min = request.form.get('alexa_min')
alexa_max = request.form.get('alexa_max')
error = False
if term is None:
error = True
if keywords is None:
error = True
if engine is None:
error = True
if driver is None:
error = True
if ignore is None:
error = True
if alexa_min is None:
error = True
if alexa_max is None:
error = True
if error is False:
alexa_min = 0
alexa_max = sys.maxsize
if request.form.get('alexa_min') != "":
alexa_min = int(request.form.get('alexa_min'))
if request.form.get('alexa_max') != "":
alexa_max = int(request.form.get('alexa_max'))
if keywords == "":
keywords = []
else:
keywords = keywords.split(',')
if ignore == "":
ignore = []
else:
ignore = ignore.split(',')
context = ScraperContext()
context.setDriver()
context.setEngine()
data = context.doSearch(searchInput= term, keywords= keywords, min_popularity= alexa_min, max_popularity= alexa_max, ignore= ignore, file= file)
return data, 200
else:
return {"error": True}, 401
if __name__ == '__main__':
app.run(host="0.0.0.0", port = 8080, debug = False)
# socketio.run(app)