-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
122 lines (100 loc) · 3.29 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
from flask import Flask
from flask.ext.mongoengine import MongoEngine
from flask.ext.mongorest import MongoRest
from flask.ext.mongorest.views import ResourceView
from flask.ext.mongorest.resources import Resource
from flask.ext.mongorest import operators as ops
from flask.ext.mongorest import methods
import os
app = Flask(__name__)
app.config.update(
MONGODB_HOST = 'localhost',
MONGODB_PORT = '27017',
MONGODB_DB = 'calidad_api',
)
db = MongoEngine(app)
api = MongoRest(app)
class Country(db.Document):
name = db.StringField()
id_country = db.StringField()
longitude = db.StringField()
latitude = db.StringField()
timezone = db.StringField()
level = db.StringField()
class City(db.Document):
name = db.StringField()
id_city = db.StringField()
longitude = db.StringField()
latitude = db.StringField()
timezone = db.StringField()
level = db.StringField()
id_country = db.StringField()
class Station(db.Document):
name = db.StringField()
id_station = db.StringField()
longitude = db.StringField()
latitude = db.StringField()
timezone = db.StringField()
level = db.StringField()
id_country = db.StringField()
id_city = db.StringField()
class Method(db.Document):
method_id = db.StringField()
method_shortdescription = db.StringField()
method_protocol = db.StringField()
method_device = db.StringField()
class Pollutant(db.Document):
station_id = db.StringField()
pollutant_id = db.StringField()
pollutant_unit = db.StringField()
pollutant_update_time = db.StringField()
pollutant_average = db.StringField()
pollutant_value = db.StringField()
class CountryResource(Resource):
document = Country
filters = {
'name': [ops.Exact, ops.Startswith]
}
class CityResource(Resource):
document = City
filters = {
'name': [ops.Exact, ops.Startswith]
}
class StationResource(Resource):
document = Station
filters = {
'name': [ops.Exact, ops.Startswith]
}
class MethodResource(Resource):
document = Method
filters = {
'name': [ops.Exact, ops.Startswith]
}
class PollutantResource(Resource):
document = Pollutant
filters = {
'name': [ops.Exact, ops.Startswith]
}
@api.register(name='countries', url='/countries/')
class CountryView(ResourceView):
resource = CountryResource
methods = [methods.Create, methods.Update, methods.Fetch, methods.List]
@api.register(name='cities', url='/cities/')
class CityView(ResourceView):
resource = CityResource
methods = [methods.Create, methods.Update, methods.Fetch, methods.List]
@api.register(name='stations', url='/stations/')
class CityView(ResourceView):
resource = StationResource
methods = [methods.Create, methods.Update, methods.Fetch, methods.List]
@api.register(name='methods', url='/methods/')
class CityView(ResourceView):
resource = MethodResource
methods = [methods.Create, methods.Update, methods.Fetch, methods.List]
@api.register(name='pollutants', url='/pollutants/')
class CityView(ResourceView):
resource = PollutantResource
methods = [methods.Create, methods.Update, methods.Fetch, methods.List]
if __name__ == "__main__":
port = int(os.environ.get('PORT', 8000))
app.run(host='0.0.0.0', port=port, debug = "true")