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
8baa05af
Commit
8baa05af
authored
Dec 20, 2016
by
Eryk Leniart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix script to add measurements
parent
76f49a63
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
4 deletions
+47
-4
cron_update_measurements.py
cron_update_measurements.py
+46
-4
requirements.txt
requirements.txt
+1
-0
No files found.
cron_update_measurements.py
View file @
8baa05af
from
db
import
DDBmeasurements
# -*- coding: utf-8 -*-
import
requests
import
time
from
tornado.ioloop
import
IOLoop
from
functools
import
partial
from
db
import
DDBstations
,
DDBtypes
,
DDBmeasurements
,
DDBlastmeasurements
from
dateutil.parser
import
parse
db_measurements
=
DDBmeasurements
()
def
get_station_by_id
(
station_id
,
station_data
):
for
station
in
station_data
:
if
str
(
station
[
'api_station_id'
])
==
station_id
:
return
station
[
'station_id'
]
def
get_type_by_name
(
type_name
,
type_data
):
for
type
in
type_data
:
if
type
[
'shortname'
]
==
type_name
:
return
type
[
'type_id'
]
def
get_timestamp_from_datetime
(
datetime_string
):
dt
=
parse
(
datetime_string
)
return
time
.
mktime
(
dt
.
timetuple
())
ioloop
=
IOLoop
.
instance
()
measurements
=
DDBmeasurements
()
last_measurements
=
DDBlastmeasurements
()
stations
=
DDBstations
()
types
=
DDBtypes
()
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
))
for
station_measurements
in
actual_data
:
for
measurement
in
station_measurements
[
'details'
]:
db_measurements
.
add
(
measurement
[
'st_id'
],
measurement
[
'par_id'
],
measurement
[
'o_value'
],
measurement
[
'o_czas'
])
\ No newline at end of file
try
:
ready_station_id
=
get_station_by_id
(
measurement
[
'st_id'
],
station_data
)
ready_type_id
=
get_type_by_name
(
measurement
[
'par_name'
],
type_data
)
ready_measurement_value
=
measurement
[
'o_value'
]
ready_measurement_timestamp
=
get_timestamp_from_datetime
(
measurement
[
'o_czas'
])
if
ready_station_id
and
ready_type_id
and
ready_measurement_value
and
ready_measurement_timestamp
:
ioloop
.
run_sync
(
partial
(
measurements
.
add
,
station_id
=
ready_station_id
,
type_id
=
ready_type_id
,
value
=
ready_measurement_value
,
measurement_time
=
ready_measurement_timestamp
))
ioloop
.
run_sync
(
partial
(
last_measurements
.
add
,
station_id
=
ready_station_id
,
type_id
=
ready_type_id
,
value
=
ready_measurement_value
,
measurement_time
=
ready_measurement_timestamp
))
except
Exception
:
pass
requirements.txt
View file @
8baa05af
requests
tornado
== 4.4.2
botocore
==0.65.0
tornado-botocore
==0.1.6
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