Merge lp:~bkerensa/weather-indicator/remove-unsupport-google-provider into lp:weather-indicator/3.0
- remove-unsupport-google-provider
- Merge into foggy
Proposed by
Benjamin Kerensa
Status: | Merged |
---|---|
Merged at revision: | 309 |
Proposed branch: | lp:~bkerensa/weather-indicator/remove-unsupport-google-provider |
Merge into: | lp:weather-indicator/3.0 |
Diff against target: |
318 lines (+1/-287) 3 files modified
AUTHORS (+1/-0) src/service/indicator_weather_service/providers/google.py (+0/-281) src/service/indicator_weather_service/weather.py (+0/-6) |
To merge this branch: | bzr merge lp:~bkerensa/weather-indicator/remove-unsupport-google-provider |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Vadim Rutkovsky | Approve | ||
Review via email: mp+135598@code.launchpad.net |
Commit message
Description of the change
Google Weather Provider API is not longer offered by Google and there has been
a open bug in Ubuntu for sometime complaining about this. I removed the provider in order to remove confusion and once this is accepted I will merge
the change into Ubuntu.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'AUTHORS' |
2 | --- AUTHORS 2011-03-28 23:49:01 +0000 |
3 | +++ AUTHORS 2012-11-22 07:34:33 +0000 |
4 | @@ -2,3 +2,4 @@ |
5 | Copyright (C) 2010 Mehdi Rejraji <mehd36@gmail.com> |
6 | Copyright (C) 2010 Vadim Rutkovsky <roignac@gmail.com> |
7 | Copyright (C) 2011 Panagiotis Skintzos <panajotis@gmail.com> |
8 | +Copyright (c) 2012 Benjamin Kerensa <bkerensa@ubuntu.com> |
9 | |
10 | === removed file 'src/service/indicator_weather_service/providers/google.py' |
11 | --- src/service/indicator_weather_service/providers/google.py 2011-05-30 09:44:41 +0000 |
12 | +++ src/service/indicator_weather_service/providers/google.py 1970-01-01 00:00:00 +0000 |
13 | @@ -1,281 +0,0 @@ |
14 | -#!/usr/bin/env python |
15 | -# -*- coding: utf-8 -*- |
16 | -### BEGIN LICENSE |
17 | -# Copyright (C) 2010 Sebastian MacDonald Sebas310@gmail.com |
18 | -# Copyright (C) 2010 Mehdi Rejraji mehd36@gmail.com |
19 | -# Copyright (C) 2011 Vadim Rutkovsky roignac@gmail.com |
20 | -# Copyright (C) 2011 Panagiotis Skintzos panajotis@gmail.com |
21 | -# |
22 | -# This program is free software: you can redistribute it and/or modify it |
23 | -# under the terms of the GNU General Public License version 3, as published |
24 | -# by the Free Software Foundation. |
25 | -# |
26 | -# This program is distributed in the hope that it will be useful, but |
27 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
28 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
29 | -# PURPOSE. See the GNU General Public License for more details. |
30 | -# |
31 | -# You should have received a copy of the GNU General Public License along |
32 | -# with this program. If not, see <http://www.gnu.org/licenses/>. |
33 | -### END LICENSE |
34 | - |
35 | - |
36 | -__all__ = [ |
37 | - 'GoogleWeather', |
38 | - ] |
39 | - |
40 | -import traceback |
41 | -import re |
42 | -import types |
43 | -import datetime |
44 | -import calendar |
45 | -import locale |
46 | -import pywapi |
47 | - |
48 | -from indicator_weather_service import * |
49 | -from indicator_weather_service.providers import WeatherProvider |
50 | -from indicator_weather_service.weather import WeatherField, WeatherSection |
51 | -from indicator_weather_service.units import MetricSystem, WindUnit |
52 | - |
53 | -import gettext |
54 | -from gettext import gettext as _ |
55 | -from gettext import ngettext as __ |
56 | -gettext.textdomain(GETTEXT_DOMAIN) |
57 | - |
58 | -class GoogleWeather(WeatherProvider): |
59 | - """ |
60 | - WeatherProvider subclass for Google weather data source |
61 | - """ |
62 | - NAME = "Google" |
63 | - |
64 | - #Available conditions by google icon |
65 | - #Format: Google icon name: (day icon, night icon, is a severe weather condition) |
66 | - CONDITIONS = { |
67 | - "sunny" : ( "weather-clear", "weather-clear-night", False), |
68 | - "mostlysunny" : ( "weather-clear", "weather-clear-night", False), |
69 | - "partlycloudy" : ( "weather-few-clouds", "weather-few-clouds-night", False), |
70 | - "mostlycloudy" : ( "weather-overcast", "weather-overcast", False), |
71 | - "overcast" : ( "weather-overcast", "weather-overcast", False), |
72 | - "cloudy" : ( "weather-clouds", "weather-clouds-night", False), |
73 | - "rain" : ( "weather-showers", "weather-showers", False), |
74 | - "chanceofrain" : ( "weather-showers", "weather-showers", False), |
75 | - "sleet" : ( "weather-snow", "weather-snow", False), |
76 | - "rainsnow" : ( "weather-snow", "weather-snow", False), |
77 | - "snow" : ( "weather-snow", "weather-snow", False), |
78 | - "chanceofsnow" : ( "weather-snow", "weather-snow", False), |
79 | - "icy" : ( "weather-snow", "weather-snow", False), |
80 | - "flurries" : ( "weather-snow", "weather-snow", False), |
81 | - "dust" : ( "weather-fog", "weather-fog", False), |
82 | - "fog" : ( "weather-fog", "weather-fog", False), |
83 | - "mist" : ( "weather-fog", "weather-fog", False), |
84 | - "smoke" : ( "weather-fog", "weather-fog", False), |
85 | - "haze" : ( "weather-fog", "weather-fog", False), |
86 | - "chanceofstorm" : ( "weather-storm", "weather-storm", True), |
87 | - "storm" : ( "weather-storm", "weather-storm", True), |
88 | - "thunderstorm" : ( "weather-storm", "weather-storm", True), |
89 | - "chanceoftstorm" : ( "weather-storm", "weather-storm", True), |
90 | - "scatteredshowers" : ( "weather-showers-scattered", "weather-showers", False), |
91 | - "scatteredthunderstorms" : ( "weather-storm", "weather-storm", True), |
92 | - } |
93 | - |
94 | - @staticmethod |
95 | - def convert_coordinate(value): |
96 | - """ |
97 | - Converts a coordinate for Google needs |
98 | - """ |
99 | - return int(round(float(value) * 1e6)) |
100 | - |
101 | - @staticmethod |
102 | - def get_location_id(location_code, location_details, log): |
103 | - """ |
104 | - Returns a location id for a specific location |
105 | - """ |
106 | - try: |
107 | - lat = GoogleWeather.convert_coordinate(location_details['latitude']) |
108 | - lon = GoogleWeather.convert_coordinate(location_details['longitude']) |
109 | - return ",,,%s,%s" % (lat, lon) |
110 | - |
111 | - except Exception, e: |
112 | - log.error(e) |
113 | - log.debug(traceback.format_exc(e)) |
114 | - return None |
115 | - |
116 | - def __init__(self, location_id, lat, lon, log): |
117 | - """ |
118 | - Initialize |
119 | - """ |
120 | - super(GoogleWeather, self).__init__(location_id, lat, lon, log) |
121 | - |
122 | - def fetch_data(self): |
123 | - """ |
124 | - Gets fresh weather data |
125 | - """ |
126 | - # get data in english locale, imperial units |
127 | - self.__report = pywapi.get_weather_from_google( |
128 | - self._location_id, hl = 'en') |
129 | - #self.log.debug("GoogleWeather: report for %s:\n%s" % \ |
130 | - #(self._location_id, self.__report)) |
131 | - # get data in current locale |
132 | - self.__localized_report = pywapi.get_weather_from_google ( |
133 | - self._location_id, hl = get_current_locale_name()) |
134 | - #self.log.debug("GoogleWeather: localized report for %s:\n%s" % \ |
135 | - #(self._location_id, self.__localized_report)) |
136 | - # parse data |
137 | - if not isinstance(self.__report, types.DictType): |
138 | - raise Exception("Invalid report") |
139 | - if not isinstance(self.__localized_report, types.DictType): |
140 | - raise Exception("Invalid report") |
141 | - return self.__parse_data() |
142 | - |
143 | - def __parse_data(self): |
144 | - """ |
145 | - Parses the received data and fills in a dict |
146 | - """ |
147 | - data = { |
148 | - WeatherSection.INFO : { |
149 | - WeatherField.SOURCE : self.NAME, |
150 | - WeatherField.METRIC_SYSTEM : MetricSystem.IMPERIAL, |
151 | - WeatherField.WIND_UNIT : WindUnit.MPH, |
152 | - } |
153 | - } |
154 | - |
155 | - item = {} |
156 | - |
157 | - # store timestamp |
158 | - item[WeatherField.TIMESTAMP] = self._get_timestamp() |
159 | - |
160 | - # get sun data |
161 | - item[WeatherField.SUNRISE], item[WeatherField.SUNSET], is_night = \ |
162 | - self._get_sun_data() |
163 | - |
164 | - # get condition text, icon, severe |
165 | - if 'current_conditions' not in self.__localized_report: |
166 | - self.log.warning("GoogleWeather: Missing section: current_conditions") |
167 | - else: |
168 | - section = self.__localized_report['current_conditions'] |
169 | - icon_name = self._extract_icon_name(section) |
170 | - if icon_name in self.CONDITIONS: |
171 | - cond = self.CONDITIONS[icon_name] |
172 | - item[WeatherField.ICON] = cond[1] if is_night else cond[0] |
173 | - item[WeatherField.SEVERE] = cond[2] |
174 | - elif icon_name in ERROR_CODES: |
175 | - item[WeatherField.ICON] = icon_name |
176 | - else: |
177 | - item[WeatherField.ICON] = self._parse_error('icon', icon_name) |
178 | - |
179 | - item[WeatherField.CONDITION] = self._extract_str( |
180 | - section, 'condition') |
181 | - |
182 | - item[WeatherField.TEMPERATURE] = self._extract_float( |
183 | - section, 'temp_f') |
184 | - |
185 | - # get humidity, wind |
186 | - if 'current_conditions' not in self.__report: |
187 | - self.log.warning("GoogleWeather: Missing section: current_conditions") |
188 | - else: |
189 | - section = self.__report['current_conditions'] |
190 | - humidity = self._extract_str(section, 'humidity') |
191 | - if humidity not in ERROR_CODES: |
192 | - m = re.match("Humidity:\s*([\d\.\,]+)\s*%", humidity) |
193 | - if m is not None: |
194 | - item[WeatherField.HUMIDITY] = float(m.group(1)) |
195 | - else: |
196 | - item[WeatherField.HUMIDITY] = \ |
197 | - self._parse_error('humidity', humidity) |
198 | - else: |
199 | - item[WeatherField.HUMIDITY] = humidity |
200 | - |
201 | - wind = self._extract_str(section, 'wind_condition') |
202 | - if wind not in ERROR_CODES: |
203 | - m = re.match("Wind:\s*([NSEW]{1,2})\s*at\s*([\d\.\,]+)\s*mph", wind) |
204 | - if m is not None: |
205 | - item[WeatherField.WIND_SPEED] = float(m.group(2)) |
206 | - item[WeatherField.WIND_DIRECTION] = m.group(1) |
207 | - else: |
208 | - item[WeatherField.WIND_SPEED] = \ |
209 | - self._parse_error('wind_condition', wind) |
210 | - item[WeatherField.WIND_DIRECTION] = ERR_GENERIC |
211 | - else: |
212 | - item[WeatherField.WIND_SPEED] = wind |
213 | - item[WeatherField.WIND_DIRECTION] = wind |
214 | - |
215 | - # store current conditions |
216 | - data[WeatherSection.CURRENT] = item |
217 | - |
218 | - # get forecast |
219 | - if 'forecasts' not in self.__report: |
220 | - self.log.warning("GoogleWeather: Missing section: forecasts") |
221 | - else: |
222 | - cal_days = self._get_calendar_days() |
223 | - for index, section in enumerate(self.__report['forecasts']): |
224 | - section_key = "forecast%d" % index |
225 | - item = {} |
226 | - day_of_week = self._extract_str(section, 'day_of_week') |
227 | - if day_of_week in cal_days: |
228 | - item[WeatherField.FORECAST_DAY] = cal_days[day_of_week] |
229 | - elif day_of_week in ERROR_CODES: |
230 | - item[WeatherField.FORECAST_DAY] = day_of_week |
231 | - else: |
232 | - item[WeatherField.FORECAST_DAY] = \ |
233 | - self._parse_error('day_of_week', day_of_week) |
234 | - |
235 | - icon_name = self._extract_icon_name(section) |
236 | - if icon_name in self.CONDITIONS: |
237 | - cond = self.CONDITIONS[icon_name] |
238 | - item[WeatherField.ICON] = cond[0] |
239 | - item[WeatherField.SEVERE] = cond[2] |
240 | - elif icon_name in ERROR_CODES: |
241 | - item[WeatherField.ICON] = icon_name |
242 | - else: |
243 | - item[WeatherField.ICON] = self._parse_error('icon', icon_name) |
244 | - |
245 | - item[WeatherField.CONDITION] = self._extract_str( |
246 | - section, 'condition') |
247 | - |
248 | - item[WeatherField.TEMPERATURE_LOW] = \ |
249 | - self._extract_float(section, 'low') |
250 | - item[WeatherField.TEMPERATURE_HIGH] = \ |
251 | - self._extract_float(section, 'high') |
252 | - |
253 | - data[section_key] = item |
254 | - |
255 | - # get localized condition text |
256 | - for index, section in enumerate(self.__localized_report['forecasts']): |
257 | - section_key = "forecast%d" % index |
258 | - data[section_key][WeatherField.CONDITION] = self._extract_str( |
259 | - section, 'condition') |
260 | - |
261 | - return data |
262 | - |
263 | - def _get_calendar_days(self): |
264 | - days = {} |
265 | - locale.setlocale(locale.LC_ALL, 'C') |
266 | - # need to reset the locale in case of anything goes wrong |
267 | - try: |
268 | - today = datetime.datetime.now() |
269 | - day_list=list(calendar.day_abbr) |
270 | - today_index = day_list.index(today.strftime("%a")) |
271 | - for index, day in enumerate(day_list): |
272 | - if index >= today_index: |
273 | - diff_days = index - today_index |
274 | - else: |
275 | - diff_days = 7 - today_index + index |
276 | - days[day] = today + datetime.timedelta(days = diff_days) |
277 | - |
278 | - except Exception, e: |
279 | - self.log.error(e) |
280 | - self.log.debug(traceback.format_exc(e)) |
281 | - days = {} |
282 | - |
283 | - locale.resetlocale() |
284 | - return days |
285 | - |
286 | - def _extract_icon_name(self, section): |
287 | - icon_name = self._extract_str(section, 'icon') |
288 | - if icon_name not in ERROR_CODES: |
289 | - m = re.match("http://g0.gstatic.com/images/icons/onebox/weather_(.+)-40\.gif", icon_name) |
290 | - if m is not None: |
291 | - icon_name = m.group(1) |
292 | - else: |
293 | - return self._parse_error('icon', icon_name) |
294 | - return icon_name |
295 | |
296 | === modified file 'src/service/indicator_weather_service/weather.py' |
297 | --- src/service/indicator_weather_service/weather.py 2012-03-12 05:14:57 +0000 |
298 | +++ src/service/indicator_weather_service/weather.py 2012-11-22 07:34:33 +0000 |
299 | @@ -48,7 +48,6 @@ |
300 | """ |
301 | # name constants - setting value |
302 | CACHE = 'CACHE' |
303 | - GOOGLE = 'G' |
304 | YAHOO = 'Y' |
305 | WEATHER_UNDERGROUND = 'WU' |
306 | WORLD_WEATHER_ONLINE = 'WWO' |
307 | @@ -61,11 +60,6 @@ |
308 | CACHE : { |
309 | INFO_CLASS : 'providers.cached.CachedWeather', |
310 | }, |
311 | - GOOGLE : { |
312 | - INFO_WIDGET : 'google', |
313 | - INFO_CLASS : 'providers.google.GoogleWeather', |
314 | - INFO_LABEL : 'google id' |
315 | - }, |
316 | YAHOO : { |
317 | INFO_WIDGET : 'yahoo', |
318 | INFO_CLASS : 'providers.yahoo.YahooWeather', |
This looks good, thanks, Benjamin.
Unfortunately I don't have Ubuntu installed now to check that changes are applied correctly, so I'll merge this without testing