-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
109 lines (88 loc) · 3.64 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
from flask import Flask, request, jsonify, send_file
from flask_cors import CORS
from io import BytesIO
import json
from import_requests import main, calculate_mean, getDataPerRegion, importGeoserver, getGeoserverStores
app = Flask(__name__)
CORS(app)
@app.route('/api/subtract_rasters', methods=['POST'])
def calculate_subtraction():
data = request.json
years = data.get('years')
month = data.get('month')
user = data.get('user')
passw = data.get('passw')
anomalie = data.get('anomalie', True)
if not years or not month or not user or not passw:
return jsonify({'error': 'The array of years and the month are required.'}), 400
result = main(years, month, user, passw, anomalie)
if result.error:
return jsonify({'error': result.error}), 400
else:
return send_file(BytesIO(result.res), mimetype='image/tiff')
@app.route('/api/global_average', methods=['POST'])
def calculate_average():
data = request.json
workspace = data.get('workspace')
mosaic_name = data.get('mosaic_name')
years = data.get('years')
month = data.get('month')
user = data.get('user')
passw = data.get('passw')
if not years or not month or not user or not passw or not workspace or not mosaic_name:
return jsonify({'error': 'The array of years and the month are required.'}), 400
result = calculate_mean(workspace, mosaic_name, years, month, user, passw)
if result.error:
return jsonify({'error': result.error}), 400
else:
return jsonify({'body': result.res}), 200
@app.route('/api/data_region', methods=['POST'])
def calculate_data_region():
data = request.json
workspace = data.get('workspace')
stores = data.get('stores')
shp_workspace = data.get('shp_workspace')
shp_store = data.get('shp_store')
dates = data.get('dates')
user = data.get('user')
passw = data.get('passw')
if not dates or not user or not passw or not workspace or not stores or not shp_workspace or not shp_store:
return jsonify({'error': 'The array of years and the month are required.'}), 400
result = getDataPerRegion(workspace, stores, dates, user, passw, shp_workspace, shp_store)
if result.error:
return jsonify({'error': result.error}), 400
else:
return jsonify({'body': result.res}), 200
@app.route('/api/import_geoserver', methods=['POST'])
def import_geoserver():
data = request.form['data']
file = request.files['file']
json_data = json.loads(data)
workspace = json_data.get('workspace')
user = json_data.get('user')
passw = json_data.get('passw')
geo_url = json_data.get("geo_url")
store = json_data.get("store")
if not user or not passw or not workspace or not store or not file:
return jsonify({'error': 'The array of years and the month are required.'}), 400
result = importGeoserver(workspace, user, passw, geo_url, store, file)
if result.error:
return jsonify({'error': result.error}), 400
else:
return jsonify({'body': result.res}), 200
@app.route('/api/get_geo_stores', methods=['POST'])
def get_stores():
data = request.json
workspace = data.get('workspace')
user = data.get('user')
passw = data.get('passw')
geo_url = data.get("geo_url")
if not user or not passw or not workspace or not geo_url:
return jsonify({'error': 'The array of years and the month are required.'}), 400
result = getGeoserverStores(workspace, user, passw, geo_url)
if result.error:
return jsonify({'error': result.error}), 400
else:
return jsonify({'body': result.res}), 200
if __name__ == '__main__':
app.run(debug=True)