-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
74 lines (63 loc) · 2.5 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
from flask import Flask, Request
from flask_restful import Api, Resource, reqparse
# from flask_cors import CORS
from flask import jsonify, request
from climate_predict import predict
from climate_data import get_climate_data
from doom_predict import doom_predict
app = Flask(__name__)
api = Api(app)
# cors = CORS(app, resources={r"/api/": {"origins": "*"}})
atmosphere_put_args = reqparse.RequestParser()
atmosphere_put_args.add_argument('Year', type=int, help='Insert Year to predict')
atmosphere_put_args.add_argument('Month', type=int, help='Insert Month to predict')
# the put req must be like this :
# {"Year" : 1993, "Month" : 11}
class Home(Resource):
def get(self):
return "api connected succesfully"
class Atmosphere(Resource):
def get(self):
get_data = doom_predict(450.00,310.00,310.00,300.00)
response = jsonify(get_data)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
def post(self):
# print(request.data)
args = dict(atmosphere_put_args.parse_args())
print(args)
if args['Year'] > 2008:
data = predict(args['Year'], args['Month'])
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
else :
data = get_climate_data(args['Year'], args['Month'])
response = jsonify(data)
response.headers.add('Access-Control-Allow-Origin', '*')
# print(response)
return response
# def options(self):
# # print(request.data)
# args = dict(atmosphere_put_args.parse_args())
# print(args)
# if args['Year'] > 2008:
# data = predict(args['Year'], args['Month'])
# response = jsonify(data)
# response.headers.add('Access-Control-Allow-Origin', '*')
# else :
# data = get_climate_data(args['Year'], args['Month'])
# response = jsonify(data)
# response.headers.add('Access-Control-Allow-Origin', '*')
# # print(response)
# return response
# class Atmosphere2(Resource):
# def get(self, Year, Month):
# get_data = doom_predict(450.00,310.00,310.00,300.00)
# response = jsonify(get_data)
# response.headers.add('Access-Control-Allow-Origin', '*')
# return response
api.add_resource(Home,"/")
api.add_resource(Atmosphere,"/atmosphere")
# api.add_resource(Atmosphere2,"/atmosphere2/<int:Year>/<int:Month>")
if __name__ == "__main__":
app.run(debug=False)