Commit 1c247c69 authored by Mattia Bondanza's avatar Mattia Bondanza

Caclulate average cloud and rain every 24h.

parent c6b72fc6
......@@ -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\tDescription\tCloud %\tRain"
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 "\t0"
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
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