Created
January 6, 2016 21:48
-
-
Save dvdme/4a30bbc977f1e321f195 to your computer and use it in GitHub Desktop.
Hot to use forecastiopy module to retrieve maximum temperature, minimum temperature and precipitation information for all daily data. Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from forecastiopy import * | |
apikey = 'YOUR_API_KEY' | |
Lisbon = [38.7252993, -9.1500364] | |
# 'units', 'lang' and 'exclude' options are optional but it is nice to ensure that | |
# the reply comes in correct language and unit. Setting the 'exclude' option | |
# reduces the reply size. If ou don't need the data, don't ask for it. | |
fio = ForecastIO.ForecastIO(apikey, | |
units=ForecastIO.ForecastIO.UNITS_SI, | |
lang=ForecastIO.ForecastIO.LANG_ENGLISH, | |
exclude=('hourly','minutely', 'flags', 'alerts'), | |
latitude=Lisbon[0], longitude=Lisbon[1]) | |
# check if daily data is present in the reply, just in case... | |
if fio.has_daily() is True: | |
daily = FIODaily.FIODaily(fio) | |
for day in xrange(0, daily.days()): | |
print 'Day', day+1 | |
# 'day' is the index of the day and day+1 is how many days | |
# the future. | |
# 'temperatureMax' is the dictionary of the key of the | |
# desired value | |
print 'Max Temperature', daily.get_day(day)['temperatureMax'] | |
print 'Min Temperature:', daily.get_day(day)['temperatureMin'] | |
print 'Precipitation Type:', daily.get_day(day)['precipType'] | |
print 'Precipitation Pobability:', daily.get_day(day)['precipProbability'] | |
print 'Precipitation Intensity', daily.get_day(day)['precipIntensity'] | |
else: | |
print 'No Daily data' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment