22 from forecastiopy
import *
38 WeatherReporterBase.__init__(self)
39 key_path = os.path.join(os.environ[
'HOME'],
40 '.config/rapp_platform/api_keys/forecast.io')
41 with open(key_path)
as key_fd:
50 geocode = geocoder.google(city)
53 fio = ForecastIO.ForecastIO(self.
_api_key,
54 units=ForecastIO.ForecastIO.UNITS_US,
55 latitude=geocode.latlng[0],
56 longitude=geocode.latlng[1])
58 fio = ForecastIO.ForecastIO(self.
_api_key,
59 units=ForecastIO.ForecastIO.UNITS_SI,
60 latitude=geocode.latlng[0],
61 longitude=geocode.latlng[1])
74 if fio.has_currently()
is True:
75 currently = FIOCurrently.FIOCurrently(fio)
78 raise RappError(
'Could not fetch current weather')
89 if fio.has_daily()
is True:
90 daily = FIODaily.FIODaily(fio)
93 raise RappError(
'Could not fetch weather forecast')
103 response[
'date'] = str(report.time)
104 response[
'temperature'] = str(report.temperature)
105 response[
'weather_description'] = str(report.summary)
106 response[
'humidity'] = str(report.humidity)
107 response[
'visibility'] = str(report.visibility)
108 response[
'pressure'] = str(report.pressure)
109 response[
'wind_speed'] = str(report.windSpeed)
110 response[
'wind_temperature'] =
''
111 response[
'wind_direction'] =
''
117 for day
in xrange(0, report.days()):
119 fore[
'high_temperature'] = \
120 str(report.get_day(day)[
'temperatureMax'])
121 fore[
'low_temperature'] = \
122 str(report.get_day(day)[
'temperatureMin'])
123 fore[
'description'] = str(report.get_day(day)[
'summary'])
124 fore[
'date'] = str(report.get_day(day)[
'time'])
125 response.append(fore)
def _get_fio_object
Perfom request for weather data.
ForecastIO weather reporter.
def fetch_current_weather
Fetch the current weather.
Base class for weather reporters.
def fetch_weather_forecast
Fetch the current weather.
def _handle_current_weather_report
Handles the server's response.
def _handle_weather_forecast_report