# -*- coding: utf-8 -*- # Copyright(C) 2010 Romain Bignon # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY 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, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import urllib2 from xml.dom import minidom # TODO store datetime objects instead of strings # from datetime import datetime from weboob.capabilities.weather import ICapWeather, CityNotFound, Current, Forecast, City from weboob.tools.backend import BaseBackend from weboob.tools.browser import BaseBrowser __all__ = ['YahooBackend'] class YahooBackend(BaseBackend, ICapWeather): NAME = 'yahoo' MAINTAINER = 'Romain Bignon' EMAIL = 'romain@weboob.org' VERSION = '0.6' DESCRIPTION = 'Yahoo' LICENSE = 'GPLv3' BROWSER = BaseBrowser WEATHER_URL = 'http://weather.yahooapis.com/forecastrss?w=%s&u=%s' SEARCH_URL = 'http://fr.meteo.yahoo.com/search/weather?p=%s' def create_default_browser(self): return self.create_browser() def iter_city_search(self, pattern): # minidom doesn't seem to work with that page #handler = urllib2.urlopen((self.SEARCH_URL % pattern).replace(' ','+')) #dom = minidom.parse(handler) #handler.close() #results = dom.getElementById('search-results') #for no in results.childNodes: # print no.nodeValue # so i use a basic but efficient parsing with self.browser: content = self.browser.readurl((self.SEARCH_URL % pattern).replace(' ','+')) page='' for line in content.split('\n'): if "