Fix conversion warning and remove useless cache

This commit is contained in:
Florent 2012-04-26 19:08:18 +02:00
commit 996f1e0c22
2 changed files with 10 additions and 17 deletions

View file

@ -34,8 +34,6 @@ class SachsenBrowser(BaseBrowser):
'.*hwz/MP/.*': HistoryPage '.*hwz/MP/.*': HistoryPage
} }
cache_list = None
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
BaseBrowser.__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') self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html')
def get_rivers_list(self): def get_rivers_list(self):
if self.cache_list is None: if not self.is_on_page(ListPage):
if not self.is_on_page(ListPage): self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html')
self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html') return self.page.get_rivers_list()
self.cache_list = self.page.get_rivers_list()
return self.cache_list
def iter_history(self, id): def iter_history(self, id):
self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/MP/%d/index.html' % int(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() return self.page.last_seen()
def search(self, pattern): def search(self, pattern):
if self.cache_list is None: for gauge in self.get_rivers_list():
self.get_rivers_list() if pattern in gauge.name or pattern in gauge.river:
for gauge in self.cache_list:
if gauge.name.__contains__(pattern) or gauge.river.__contains__(pattern):
yield gauge yield gauge

View file

@ -31,8 +31,8 @@ class ListPage(BasePage):
for pegel in self.document.getroot().xpath(".//a[@onmouseout='pegelaus()']"): for pegel in self.document.getroot().xpath(".//a[@onmouseout='pegelaus()']"):
data = pegel.attrib['onmouseover'].strip('pegelein(').strip(')').replace(",'", ",").split("',") data = pegel.attrib['onmouseover'].strip('pegelein(').strip(')').replace(",'", ",").split("',")
gauge = Gauge(int(data[7])) gauge = Gauge(int(data[7]))
gauge.name = data[0].strip("'") gauge.name = unicode(data[0].strip("'"))
gauge.river = data[1] gauge.river = unicode(data[1])
try: try:
lastdate = date(*reversed([int(x) for x in data[2].split(' ')[0].split(".")])) 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(":")]) lasttime = time(*[int(x) for x in data[2].split(' ')[1].split(":")])
@ -49,11 +49,11 @@ class ListPage(BasePage):
gauge.flow = NotAvailable gauge.flow = NotAvailable
bildforecast = data[5] bildforecast = data[5]
if bildforecast == "pf_gerade.png": if bildforecast == "pf_gerade.png":
gauge.forecast = "stable" gauge.forecast = u"stable"
elif bildforecast == "pf_unten.png": elif bildforecast == "pf_unten.png":
gauge.forecast = "Go down" gauge.forecast = u"Go down"
elif bildforecast == "pf_oben.png": elif bildforecast == "pf_oben.png":
gauge.forecast = "Go up" gauge.forecast = u"Go up"
else: else:
gauge.forecast = NotAvailable gauge.forecast = NotAvailable