Project

General

Profile

1
from flask import Flask
2
from flask import jsonify, request
3
from eu.dnetlib.exporter.ScrollResult import ScrollResult
4
from eu.dnetlib.exporter.dataciteExporter import is_available
5

    
6
app = Flask(__name__)
7

    
8
scroll_map = {}
9

    
10

    
11
@app.route("/new_scan", methods=['get'])
12
def new_scan():
13
    timestamp = request.args.get('timestamp')
14
    print(timestamp)
15
    active = request.args.get('active')
16
    if active is not None and 'false' == active.lower():
17
        active = False
18
    else:
19
        active = True
20
    s = ScrollResult()
21
    s.generate_scroll(timestamp=timestamp, only_active=active)
22
    scroll_map[str(s.id)] = s
23
    return jsonify(s.next_page())
24

    
25

    
26
@app.route("/scan/<s_id>")
27
def continue_scan(s_id):
28
    if s_id in scroll_map:
29
        try:
30
            return jsonify(scroll_map[s_id].next_page())
31
        except Exception as e:
32
            print(e)
33
            del(scroll_map[s_id])
34
            return jsonify([])
35
    return jsonify([])
36

    
37

    
38
@app.route("/status", methods=['get'])
39
def get_status():
40
    try:
41
        if is_available() :
42
            return jsonify(dict(status = 'OK'))    
43
    except:
44
        pass
45
    return jsonify(dict(status = 'FAIL'))
46
    
47

    
48

    
49

    
50
if __name__ == '__main__':
51
    print("Starting flask")
52
    app.run(host='0.0.0.0', debug=False)
(1-1/2)