Commit 8165a91f authored by Florent Fourcot's avatar Florent Fourcot

Pep8 cleaning

parent 3daf7af5
......@@ -21,7 +21,8 @@
from __future__ import with_statement
from .browser import SachsenBrowser
from weboob.capabilities.gauge import ICapGauge, GaugeSensor, Gauge, SensorNotFound
from weboob.capabilities.gauge import ICapGauge, GaugeSensor, Gauge,\
SensorNotFound
from weboob.tools.backend import BaseBackend
......@@ -44,7 +45,8 @@ class SachsenLevelBackend(BaseBackend, ICapGauge):
else:
lowpattern = pattern.lower()
for gauge in self.browser.get_rivers_list():
if lowpattern in gauge.name.lower() or lowpattern in gauge.object.lower():
if lowpattern in gauge.name.lower()\
or lowpattern in gauge.object.lower():
yield gauge
def _get_gauge_by_id(self, id):
......
......@@ -34,17 +34,20 @@ class SachsenBrowser(BaseBrowser):
'.*hwz/MP/.*': HistoryPage
}
homepage = '/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html'
def __init__(self, *args, **kwargs):
BaseBrowser.__init__(self, *args, **kwargs)
def home(self):
self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html')
self.location(self.homepage)
def get_rivers_list(self):
if not self.is_on_page(ListPage):
self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html')
self.location(self.homepage)
return self.page.get_rivers_list()
def iter_history(self, sensor):
self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/MP/%d/index.html' % int(sensor.gaugeid))
self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/MP/%d/index.html'
% int(sensor.gaugeid))
return self.page.iter_history(sensor)
......@@ -27,24 +27,28 @@ __all__ = ['ListPage', 'HistoryPage']
class ListPage(BasePage):
alarmlevel = {"as1.gif": u"Alarmstufe 1", "as2.gif": u"Alarmstufe 2", \
"as3.gif": u"Alarmstufe 3", "as4.gig": u"Alarmstufe 4", \
"qua_grau.gif": u"No alarm function", "p_gruen.gif": u"", \
alarmlevel = {"as1.gif": u"Alarmstufe 1", "as2.gif": u"Alarmstufe 2",
"as3.gif": u"Alarmstufe 3", "as4.gig": u"Alarmstufe 4",
"qua_grau.gif": u"No alarm function", "p_gruen.gif": u"",
"qua_weiss.gif": u"no data"}
def get_rivers_list(self):
for pegel in self.document.getroot().xpath(".//a[@onmouseout='pegelaus()']"):
div = pegel.getparent()
img = div.find('.//img').attrib['src'].split('/')[1]
data = pegel.attrib['onmouseover'].strip('pegelein(').strip(')').replace(",'", ",").split("',")
data = pegel.attrib['onmouseover']\
.strip('pegelein(').strip(')').replace(",'", ",").split("',")
gauge = Gauge(int(data[7]))
gauge.name = unicode(data[0].strip("'"))
gauge.city = gauge.name.split(' ')[0] # TODO: real regexp to remove the number
gauge.city = gauge.name.split(' ')[0]
gauge.object = unicode(data[1])
sensors = []
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(":")])
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(":")])
lastdate = datetime.combine(lastdate, lasttime)
except:
lastdate = NotAvailable
......@@ -106,8 +110,10 @@ class HistoryPage(BasePage):
lines.pop(0) # remove first value (already in lastvalue)
for line in lines:
history = GaugeMeasure()
leveldate = date(*reversed([int(x) for x in line[0].text_content().split(' ')[0].split(".")]))
leveltime = time(*[int(x) for x in line[0].text_content().split(' ')[1].split(":")])
leveldate = date(*reversed([int(x)
for x in line[0].text_content().split(' ')[0].split(".")]))
leveltime = time(*[int(x)
for x in line[0].text_content().split(' ')[1].split(":")])
history.date = datetime.combine(leveldate, leveltime)
if sensor.name == u"Level":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment