weather-indicator-team team mailing list archive
-
weather-indicator-team team
-
Mailing list archive
-
Message #00124
lp:~bkerensa/weather-indicator/remove-unsupport-google-provider into lp:weather-indicator
Benjamin Kerensa has proposed merging lp:~bkerensa/weather-indicator/remove-unsupport-google-provider into lp:weather-indicator.
Requested reviews:
Weather Indicator Team (weather-indicator-team)
For more details, see:
https://code.launchpad.net/~bkerensa/weather-indicator/remove-unsupport-google-provider/+merge/135598
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.
--
https://code.launchpad.net/~bkerensa/weather-indicator/remove-unsupport-google-provider/+merge/135598
Your team Weather Indicator Team is requested to review the proposed merge of lp:~bkerensa/weather-indicator/remove-unsupport-google-provider into lp:weather-indicator.
=== modified file 'AUTHORS'
--- AUTHORS 2011-03-28 23:49:01 +0000
+++ AUTHORS 2012-11-22 07:34:33 +0000
@@ -2,3 +2,4 @@
Copyright (C) 2010 Mehdi Rejraji <mehd36@xxxxxxxxx>
Copyright (C) 2010 Vadim Rutkovsky <roignac@xxxxxxxxx>
Copyright (C) 2011 Panagiotis Skintzos <panajotis@xxxxxxxxx>
+Copyright (c) 2012 Benjamin Kerensa <bkerensa@xxxxxxxxxx>
=== removed file 'src/service/indicator_weather_service/providers/google.py'
--- src/service/indicator_weather_service/providers/google.py 2011-05-30 09:44:41 +0000
+++ src/service/indicator_weather_service/providers/google.py 1970-01-01 00:00:00 +0000
@@ -1,281 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-### BEGIN LICENSE
-# Copyright (C) 2010 Sebastian MacDonald Sebas310@xxxxxxxxx
-# Copyright (C) 2010 Mehdi Rejraji mehd36@xxxxxxxxx
-# Copyright (C) 2011 Vadim Rutkovsky roignac@xxxxxxxxx
-# Copyright (C) 2011 Panagiotis Skintzos panajotis@xxxxxxxxx
-#
-# This program is free software: you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 3, as published
-# by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranties of
-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program. If not, see <http://www.gnu.org/licenses/>.
-### END LICENSE
-
-
-__all__ = [
- 'GoogleWeather',
- ]
-
-import traceback
-import re
-import types
-import datetime
-import calendar
-import locale
-import pywapi
-
-from indicator_weather_service import *
-from indicator_weather_service.providers import WeatherProvider
-from indicator_weather_service.weather import WeatherField, WeatherSection
-from indicator_weather_service.units import MetricSystem, WindUnit
-
-import gettext
-from gettext import gettext as _
-from gettext import ngettext as __
-gettext.textdomain(GETTEXT_DOMAIN)
-
-class GoogleWeather(WeatherProvider):
- """
- WeatherProvider subclass for Google weather data source
- """
- NAME = "Google"
-
- #Available conditions by google icon
- #Format: Google icon name: (day icon, night icon, is a severe weather condition)
- CONDITIONS = {
- "sunny" : ( "weather-clear", "weather-clear-night", False),
- "mostlysunny" : ( "weather-clear", "weather-clear-night", False),
- "partlycloudy" : ( "weather-few-clouds", "weather-few-clouds-night", False),
- "mostlycloudy" : ( "weather-overcast", "weather-overcast", False),
- "overcast" : ( "weather-overcast", "weather-overcast", False),
- "cloudy" : ( "weather-clouds", "weather-clouds-night", False),
- "rain" : ( "weather-showers", "weather-showers", False),
- "chanceofrain" : ( "weather-showers", "weather-showers", False),
- "sleet" : ( "weather-snow", "weather-snow", False),
- "rainsnow" : ( "weather-snow", "weather-snow", False),
- "snow" : ( "weather-snow", "weather-snow", False),
- "chanceofsnow" : ( "weather-snow", "weather-snow", False),
- "icy" : ( "weather-snow", "weather-snow", False),
- "flurries" : ( "weather-snow", "weather-snow", False),
- "dust" : ( "weather-fog", "weather-fog", False),
- "fog" : ( "weather-fog", "weather-fog", False),
- "mist" : ( "weather-fog", "weather-fog", False),
- "smoke" : ( "weather-fog", "weather-fog", False),
- "haze" : ( "weather-fog", "weather-fog", False),
- "chanceofstorm" : ( "weather-storm", "weather-storm", True),
- "storm" : ( "weather-storm", "weather-storm", True),
- "thunderstorm" : ( "weather-storm", "weather-storm", True),
- "chanceoftstorm" : ( "weather-storm", "weather-storm", True),
- "scatteredshowers" : ( "weather-showers-scattered", "weather-showers", False),
- "scatteredthunderstorms" : ( "weather-storm", "weather-storm", True),
- }
-
- @staticmethod
- def convert_coordinate(value):
- """
- Converts a coordinate for Google needs
- """
- return int(round(float(value) * 1e6))
-
- @staticmethod
- def get_location_id(location_code, location_details, log):
- """
- Returns a location id for a specific location
- """
- try:
- lat = GoogleWeather.convert_coordinate(location_details['latitude'])
- lon = GoogleWeather.convert_coordinate(location_details['longitude'])
- return ",,,%s,%s" % (lat, lon)
-
- except Exception, e:
- log.error(e)
- log.debug(traceback.format_exc(e))
- return None
-
- def __init__(self, location_id, lat, lon, log):
- """
- Initialize
- """
- super(GoogleWeather, self).__init__(location_id, lat, lon, log)
-
- def fetch_data(self):
- """
- Gets fresh weather data
- """
- # get data in english locale, imperial units
- self.__report = pywapi.get_weather_from_google(
- self._location_id, hl = 'en')
- #self.log.debug("GoogleWeather: report for %s:\n%s" % \
- #(self._location_id, self.__report))
- # get data in current locale
- self.__localized_report = pywapi.get_weather_from_google (
- self._location_id, hl = get_current_locale_name())
- #self.log.debug("GoogleWeather: localized report for %s:\n%s" % \
- #(self._location_id, self.__localized_report))
- # parse data
- if not isinstance(self.__report, types.DictType):
- raise Exception("Invalid report")
- if not isinstance(self.__localized_report, types.DictType):
- raise Exception("Invalid report")
- return self.__parse_data()
-
- def __parse_data(self):
- """
- Parses the received data and fills in a dict
- """
- data = {
- WeatherSection.INFO : {
- WeatherField.SOURCE : self.NAME,
- WeatherField.METRIC_SYSTEM : MetricSystem.IMPERIAL,
- WeatherField.WIND_UNIT : WindUnit.MPH,
- }
- }
-
- item = {}
-
- # store timestamp
- item[WeatherField.TIMESTAMP] = self._get_timestamp()
-
- # get sun data
- item[WeatherField.SUNRISE], item[WeatherField.SUNSET], is_night = \
- self._get_sun_data()
-
- # get condition text, icon, severe
- if 'current_conditions' not in self.__localized_report:
- self.log.warning("GoogleWeather: Missing section: current_conditions")
- else:
- section = self.__localized_report['current_conditions']
- icon_name = self._extract_icon_name(section)
- if icon_name in self.CONDITIONS:
- cond = self.CONDITIONS[icon_name]
- item[WeatherField.ICON] = cond[1] if is_night else cond[0]
- item[WeatherField.SEVERE] = cond[2]
- elif icon_name in ERROR_CODES:
- item[WeatherField.ICON] = icon_name
- else:
- item[WeatherField.ICON] = self._parse_error('icon', icon_name)
-
- item[WeatherField.CONDITION] = self._extract_str(
- section, 'condition')
-
- item[WeatherField.TEMPERATURE] = self._extract_float(
- section, 'temp_f')
-
- # get humidity, wind
- if 'current_conditions' not in self.__report:
- self.log.warning("GoogleWeather: Missing section: current_conditions")
- else:
- section = self.__report['current_conditions']
- humidity = self._extract_str(section, 'humidity')
- if humidity not in ERROR_CODES:
- m = re.match("Humidity:\s*([\d\.\,]+)\s*%", humidity)
- if m is not None:
- item[WeatherField.HUMIDITY] = float(m.group(1))
- else:
- item[WeatherField.HUMIDITY] = \
- self._parse_error('humidity', humidity)
- else:
- item[WeatherField.HUMIDITY] = humidity
-
- wind = self._extract_str(section, 'wind_condition')
- if wind not in ERROR_CODES:
- m = re.match("Wind:\s*([NSEW]{1,2})\s*at\s*([\d\.\,]+)\s*mph", wind)
- if m is not None:
- item[WeatherField.WIND_SPEED] = float(m.group(2))
- item[WeatherField.WIND_DIRECTION] = m.group(1)
- else:
- item[WeatherField.WIND_SPEED] = \
- self._parse_error('wind_condition', wind)
- item[WeatherField.WIND_DIRECTION] = ERR_GENERIC
- else:
- item[WeatherField.WIND_SPEED] = wind
- item[WeatherField.WIND_DIRECTION] = wind
-
- # store current conditions
- data[WeatherSection.CURRENT] = item
-
- # get forecast
- if 'forecasts' not in self.__report:
- self.log.warning("GoogleWeather: Missing section: forecasts")
- else:
- cal_days = self._get_calendar_days()
- for index, section in enumerate(self.__report['forecasts']):
- section_key = "forecast%d" % index
- item = {}
- day_of_week = self._extract_str(section, 'day_of_week')
- if day_of_week in cal_days:
- item[WeatherField.FORECAST_DAY] = cal_days[day_of_week]
- elif day_of_week in ERROR_CODES:
- item[WeatherField.FORECAST_DAY] = day_of_week
- else:
- item[WeatherField.FORECAST_DAY] = \
- self._parse_error('day_of_week', day_of_week)
-
- icon_name = self._extract_icon_name(section)
- if icon_name in self.CONDITIONS:
- cond = self.CONDITIONS[icon_name]
- item[WeatherField.ICON] = cond[0]
- item[WeatherField.SEVERE] = cond[2]
- elif icon_name in ERROR_CODES:
- item[WeatherField.ICON] = icon_name
- else:
- item[WeatherField.ICON] = self._parse_error('icon', icon_name)
-
- item[WeatherField.CONDITION] = self._extract_str(
- section, 'condition')
-
- item[WeatherField.TEMPERATURE_LOW] = \
- self._extract_float(section, 'low')
- item[WeatherField.TEMPERATURE_HIGH] = \
- self._extract_float(section, 'high')
-
- data[section_key] = item
-
- # get localized condition text
- for index, section in enumerate(self.__localized_report['forecasts']):
- section_key = "forecast%d" % index
- data[section_key][WeatherField.CONDITION] = self._extract_str(
- section, 'condition')
-
- return data
-
- def _get_calendar_days(self):
- days = {}
- locale.setlocale(locale.LC_ALL, 'C')
- # need to reset the locale in case of anything goes wrong
- try:
- today = datetime.datetime.now()
- day_list=list(calendar.day_abbr)
- today_index = day_list.index(today.strftime("%a"))
- for index, day in enumerate(day_list):
- if index >= today_index:
- diff_days = index - today_index
- else:
- diff_days = 7 - today_index + index
- days[day] = today + datetime.timedelta(days = diff_days)
-
- except Exception, e:
- self.log.error(e)
- self.log.debug(traceback.format_exc(e))
- days = {}
-
- locale.resetlocale()
- return days
-
- def _extract_icon_name(self, section):
- icon_name = self._extract_str(section, 'icon')
- if icon_name not in ERROR_CODES:
- m = re.match("http://g0.gstatic.com/images/icons/onebox/weather_(.+)-40\.gif", icon_name)
- if m is not None:
- icon_name = m.group(1)
- else:
- return self._parse_error('icon', icon_name)
- return icon_name
=== modified file 'src/service/indicator_weather_service/weather.py'
--- src/service/indicator_weather_service/weather.py 2012-03-12 05:14:57 +0000
+++ src/service/indicator_weather_service/weather.py 2012-11-22 07:34:33 +0000
@@ -48,7 +48,6 @@
"""
# name constants - setting value
CACHE = 'CACHE'
- GOOGLE = 'G'
YAHOO = 'Y'
WEATHER_UNDERGROUND = 'WU'
WORLD_WEATHER_ONLINE = 'WWO'
@@ -61,11 +60,6 @@
CACHE : {
INFO_CLASS : 'providers.cached.CachedWeather',
},
- GOOGLE : {
- INFO_WIDGET : 'google',
- INFO_CLASS : 'providers.google.GoogleWeather',
- INFO_LABEL : 'google id'
- },
YAHOO : {
INFO_WIDGET : 'yahoo',
INFO_CLASS : 'providers.yahoo.YahooWeather',
Follow ups