From 996f1e0c22b8a52019a14a8bcfe915c8e9dfa23c Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 26 Apr 2012 19:08:18 +0200 Subject: [PATCH] Fix conversion warning and remove useless cache --- modules/sachsen/browser.py | 17 +++++------------ modules/sachsen/pages.py | 10 +++++----- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/modules/sachsen/browser.py b/modules/sachsen/browser.py index 392c38f6..7657f327 100644 --- a/modules/sachsen/browser.py +++ b/modules/sachsen/browser.py @@ -34,8 +34,6 @@ class SachsenBrowser(BaseBrowser): '.*hwz/MP/.*': HistoryPage } - cache_list = None - def __init__(self, *args, **kwargs): BaseBrowser.__init__(self, *args, **kwargs) @@ -43,11 +41,9 @@ class SachsenBrowser(BaseBrowser): self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html') def get_rivers_list(self): - if self.cache_list is None: - if not self.is_on_page(ListPage): - self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html') - self.cache_list = self.page.get_rivers_list() - return self.cache_list + if not self.is_on_page(ListPage): + self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html') + return self.page.get_rivers_list() def iter_history(self, id): self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/MP/%d/index.html' % int(id)) @@ -58,9 +54,6 @@ class SachsenBrowser(BaseBrowser): return self.page.last_seen() def search(self, pattern): - if self.cache_list is None: - self.get_rivers_list() - - for gauge in self.cache_list: - if gauge.name.__contains__(pattern) or gauge.river.__contains__(pattern): + for gauge in self.get_rivers_list(): + if pattern in gauge.name or pattern in gauge.river: yield gauge diff --git a/modules/sachsen/pages.py b/modules/sachsen/pages.py index 7bc5df93..0030fff0 100644 --- a/modules/sachsen/pages.py +++ b/modules/sachsen/pages.py @@ -31,8 +31,8 @@ class ListPage(BasePage): for pegel in self.document.getroot().xpath(".//a[@onmouseout='pegelaus()']"): data = pegel.attrib['onmouseover'].strip('pegelein(').strip(')').replace(",'", ",").split("',") gauge = Gauge(int(data[7])) - gauge.name = data[0].strip("'") - gauge.river = data[1] + gauge.name = unicode(data[0].strip("'")) + gauge.river = unicode(data[1]) try: lastdate = date(*reversed([int(x) for x in data[2].split(' ')[0].split(".")])) lasttime = time(*[int(x) for x in data[2].split(' ')[1].split(":")]) @@ -49,11 +49,11 @@ class ListPage(BasePage): gauge.flow = NotAvailable bildforecast = data[5] if bildforecast == "pf_gerade.png": - gauge.forecast = "stable" + gauge.forecast = u"stable" elif bildforecast == "pf_unten.png": - gauge.forecast = "Go down" + gauge.forecast = u"Go down" elif bildforecast == "pf_oben.png": - gauge.forecast = "Go up" + gauge.forecast = u"Go up" else: gauge.forecast = NotAvailable