-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
46 lines (34 loc) · 1.24 KB
/
api.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
import json
import webapp2
from modules import povcal
from modules import forests
class PovcalHandler(webapp2.RequestHandler):
def get(self):
# headers
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
self.response.headers['Content-Type'] = 'application/json'
# parameters
country = self.request.get('country')
povline = float(self.request.get('povline'))
proportion = bool(self.request.get('proportion', False))
# response
res = povcal.constructor(country, povline, proportion=proportion)
self.response.write(json.dumps(res))
class ForestHandler(webapp2.RequestHandler):
def get(self):
# headers
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
self.response.headers['Content-Type'] = 'application/json'
# parameters
country = self.request.get('country')
begin = self.request.get('begin')
end = self.request.get('end')
# response
res = forests.constructor(country, begin, end)
self.response.write(json.dumps(res))
handlers = webapp2.WSGIApplication(
[
('/1/povcal', PovcalHandler),
('/15/forma', ForestHandler)
], debug=True
)