1
|
from flask import Flask
|
2
|
from flask import jsonify, request
|
3
|
from eu.dnetlib.exporter.ScrollResult import ScrollResult
|
4
|
|
5
|
app = Flask(__name__)
|
6
|
|
7
|
scroll_map = {}
|
8
|
|
9
|
|
10
|
@app.route("/new_scan", methods=['get'])
|
11
|
def new_scan():
|
12
|
timestamp = request.args.get('timestamp')
|
13
|
print(timestamp)
|
14
|
active = request.args.get('active')
|
15
|
if active is not None and 'false' == active.lower():
|
16
|
active = False
|
17
|
else:
|
18
|
active = True
|
19
|
s = ScrollResult()
|
20
|
s.generate_scroll(timestamp=timestamp, only_active=active)
|
21
|
scroll_map[str(s.id)] = s
|
22
|
return jsonify(s.next_page())
|
23
|
|
24
|
|
25
|
@app.route("/scan/<s_id>")
|
26
|
def continue_scan(s_id):
|
27
|
if s_id in scroll_map:
|
28
|
try:
|
29
|
return jsonify(scroll_map[s_id].next_page())
|
30
|
except Exception as e:
|
31
|
print(e)
|
32
|
del(scroll_map[s_id])
|
33
|
return jsonify([])
|
34
|
return jsonify([])
|
35
|
|
36
|
|
37
|
if __name__ == '__main__':
|
38
|
print("Starting flask")
|
39
|
app.run(host='0.0.0.0', debug=False)
|