Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
biondo
router-forecast-led
Commits
1c247c69
Commit
1c247c69
authored
Feb 21, 2017
by
Mattia Bondanza
Browse files
Caclulate average cloud and rain every 24h.
parent
c6b72fc6
Changes
1
Hide whitespace changes
Inline
Side-by-side
pycurltest.py
View file @
1c247c69
...
...
@@ -2,6 +2,12 @@ import pycurl
import
json
from
StringIO
import
StringIO
#---- SETTINGS ----#
rain_limit
=
1.0
cloud_limit
=
50
#------------------#
buffer
=
StringIO
()
c
=
pycurl
.
Curl
()
c
.
setopt
(
c
.
URL
,
'api.openweathermap.org/data/2.5/forecast?q=pisa,it&APPID=c5ebd88f4494c472f3032e3426b6f0c6'
)
...
...
@@ -11,7 +17,35 @@ c.close()
body
=
buffer
.
getvalue
()
parsed
=
json
.
loads
(
body
)
for
i
in
parsed
[
"list"
]:
print
i
[
"dt_txt"
],
" "
,
i
[
"weather"
][
0
][
"description"
]
cloud_perc_average
=
0
rain_average
=
0
print
"Date
\t\t\t
Description
\t
Cloud %
\t
Rain"
for
i
in
range
(
len
(
parsed
[
"list"
])):
print
parsed
[
"list"
][
i
][
"dt_txt"
],
"
\t
"
,
parsed
[
"list"
][
i
][
"weather"
][
0
][
"description"
],
"
\t
"
,
parsed
[
"list"
][
i
][
"clouds"
][
"all"
],
cloud_perc_average
+=
parsed
[
"list"
][
i
][
"clouds"
][
"all"
]
if
len
(
parsed
[
"list"
][
i
][
"rain"
])
>
0
:
print
"
\t
"
,
parsed
[
"list"
][
i
][
"rain"
][
"3h"
]
rain_average
+=
parsed
[
"list"
][
i
][
"rain"
][
"3h"
]
else
:
print
"
\t
0"
if
i
%
8
==
7
:
cloud_perc_average
/=
8
rain_average
/=
8
if
cloud_perc_average
>
cloud_limit
:
print
"
\x1b
[37;1m"
,
print
"Average clouds in the last 24h: "
,
cloud_perc_average
,
"
\x1b
[0m"
if
rain_average
>
rain_limit
:
print
"
\x1b
[34m"
,
print
"Average rain in the last 24h: "
,
rain_average
,
"
\n
"
,
"
\x1b
[0m"
rain_average
=
0
cloud_perc_average
=
0
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