Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
smogonet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dominik Rosiek
smogonet
Commits
1dbe5473
Commit
1dbe5473
authored
Dec 20, 2016
by
Dominik Rosiek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
it works
parent
9a35b066
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
17 deletions
+22
-17
cron_update_measurements.py
cron_update_measurements.py
+16
-15
measurement_viewer.py
measurement_viewer.py
+6
-2
No files found.
cron_update_measurements.py
View file @
1dbe5473
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
uuid
import
UUID
import
requests
import
requests
import
time
import
time
from
tornado.ioloop
import
IOLoop
from
tornado.ioloop
import
IOLoop
...
@@ -8,17 +10,19 @@ from dateutil.parser import parse
...
@@ -8,17 +10,19 @@ from dateutil.parser import parse
import
models
import
models
from
tornado.gen
import
coroutine
from
tornado.gen
import
coroutine
def
get_station_by_id
(
station_id
,
station_data
):
def
get_station_by_id
(
station_id
,
station_data
):
for
station
in
station_data
:
station_id
=
str
(
UUID
(
int
=
int
(
station_id
)))
if
str
(
station
[
'api_station_id'
])
==
station_id
:
return
station_data
[
station_id
]
return
models
.
Station
.
get
(
station
[
'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
):
def
get_type_by_name
(
type_name
,
type_data
):
for
type
in
type_data
:
for
type
in
type_data
.
values
()
:
if
type
[
'shortname'
]
==
type_name
:
if
type
.
shortname
==
type_name
:
return
models
.
Type
.
get
(
type
[
'type_id'
])
return
type
def
get_timestamp_from_datetime
(
datetime_string
):
def
get_timestamp_from_datetime
(
datetime_string
):
...
@@ -27,17 +31,14 @@ def get_timestamp_from_datetime(datetime_string):
...
@@ -27,17 +31,14 @@ def get_timestamp_from_datetime(datetime_string):
@
coroutine
@
coroutine
def
main
(
ioloop
):
def
main
():
stations
=
DDBstations
()
types
=
DDBtypes
()
apiURL
=
"http://powietrze.malopolska.pl/_powietrzeapi/api/dane?act=danemiasta&ci_id=1"
apiURL
=
"http://powietrze.malopolska.pl/_powietrzeapi/api/dane?act=danemiasta&ci_id=1"
r
=
requests
.
get
(
apiURL
)
r
=
requests
.
get
(
apiURL
)
actual_data
=
r
.
json
()[
'dane'
][
'actual'
]
actual_data
=
r
.
json
()[
'dane'
][
'actual'
]
station_data
=
ioloop
.
run_sync
(
partial
(
stations
.
get_all
)
)
station_data
=
yield
models
.
Station
.
get_all
(
)
type_data
=
ioloop
.
run_sync
(
partial
(
types
.
get_all
)
)
type_data
=
yield
models
.
Type
.
get_all
(
)
for
station_measurements
in
actual_data
:
for
station_measurements
in
actual_data
:
for
measurement
in
station_measurements
[
'details'
]:
for
measurement
in
station_measurements
[
'details'
]:
...
@@ -51,5 +52,5 @@ def main(ioloop):
...
@@ -51,5 +52,5 @@ def main(ioloop):
value
=
ready_measurement_value
,
time
=
ready_measurement_timestamp
)
value
=
ready_measurement_value
,
time
=
ready_measurement_timestamp
)
yield
measurement
.
save
()
yield
measurement
.
save
()
ioloop
=
IOLoop
.
instance
()
#
ioloop = IOLoop.instance()
IOLoop
.
current
()
.
run_sync
(
main
(
ioloop
)
)
IOLoop
.
current
()
.
run_sync
(
main
)
measurement_viewer.py
View file @
1dbe5473
...
@@ -14,8 +14,12 @@ class MainHandler(tornado.web.RequestHandler):
...
@@ -14,8 +14,12 @@ class MainHandler(tornado.web.RequestHandler):
for
station
in
stations
.
values
():
for
station
in
stations
.
values
():
for
pollution
in
pollutions
.
values
():
for
pollution
in
pollutions
.
values
():
measurement
=
yield
models
.
Measurement
.
get_last
(
station
,
pollution
)
try
:
self
.
write
(
str
(
measurement
))
self
.
write
(
"
\n
"
)
measurement
=
yield
models
.
Measurement
.
get_last
(
station
,
pollution
)
self
.
write
(
str
(
measurement
))
except
:
pass
def
make_app
():
def
make_app
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment