Commit 1dbe5473 authored by Dominik Rosiek's avatar Dominik Rosiek

it works

parent 9a35b066
# -*- coding: utf-8 -*-
from uuid import UUID
import requests
import time
from tornado.ioloop import IOLoop
......@@ -8,17 +10,19 @@ from dateutil.parser import parse
import models
from tornado.gen import coroutine
def get_station_by_id(station_id, station_data):
for station in station_data:
if str(station['api_station_id']) == station_id:
return models.Station.get(station['station_id'])
station_id = str(UUID(int=int(station_id)))
return station_data[station_id]
# for station in station_data:
# if str(station['api_station_id']) == station_id:
# result = yield models.Station.get(station['station_id'])
# return result
def get_type_by_name(type_name, type_data):
for type in type_data:
if type['shortname'] == type_name:
return models.Type.get(type['type_id'])
for type in type_data.values():
if type.shortname == type_name:
return type
def get_timestamp_from_datetime(datetime_string):
......@@ -27,17 +31,14 @@ def get_timestamp_from_datetime(datetime_string):
@coroutine
def main(ioloop):
stations = DDBstations()
types = DDBtypes()
def main():
apiURL = "http://powietrze.malopolska.pl/_powietrzeapi/api/dane?act=danemiasta&ci_id=1"
r = requests.get(apiURL)
actual_data = r.json()['dane']['actual']
station_data = ioloop.run_sync(partial(stations.get_all))
type_data = ioloop.run_sync(partial(types.get_all))
station_data = yield models.Station.get_all()
type_data = yield models.Type.get_all()
for station_measurements in actual_data:
for measurement in station_measurements['details']:
......@@ -51,5 +52,5 @@ def main(ioloop):
value=ready_measurement_value, time=ready_measurement_timestamp)
yield measurement.save()
ioloop = IOLoop.instance()
IOLoop.current().run_sync(main(ioloop))
# ioloop = IOLoop.instance()
IOLoop.current().run_sync(main)
......@@ -14,8 +14,12 @@ class MainHandler(tornado.web.RequestHandler):
for station in stations.values():
for pollution in pollutions.values():
try:
self.write("\n")
measurement = yield models.Measurement.get_last(station, pollution)
self.write(str(measurement))
except:
pass
def make_app():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment