Pep8 cleaning
This commit is contained in:
parent
3daf7af5a9
commit
8165a91ff3
3 changed files with 25 additions and 14 deletions
|
|
@ -21,7 +21,8 @@
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from .browser import SachsenBrowser
|
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
|
from weboob.tools.backend import BaseBackend
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,7 +45,8 @@ class SachsenLevelBackend(BaseBackend, ICapGauge):
|
||||||
else:
|
else:
|
||||||
lowpattern = pattern.lower()
|
lowpattern = pattern.lower()
|
||||||
for gauge in self.browser.get_rivers_list():
|
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
|
yield gauge
|
||||||
|
|
||||||
def _get_gauge_by_id(self, id):
|
def _get_gauge_by_id(self, id):
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,20 @@ class SachsenBrowser(BaseBrowser):
|
||||||
'.*hwz/MP/.*': HistoryPage
|
'.*hwz/MP/.*': HistoryPage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
homepage = '/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
BaseBrowser.__init__(self, *args, **kwargs)
|
BaseBrowser.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def home(self):
|
def home(self):
|
||||||
self.location('/de/wu/umwelt/lfug/lfug-internet/hwz/inhalt_re.html')
|
self.location(self.homepage)
|
||||||
|
|
||||||
def get_rivers_list(self):
|
def get_rivers_list(self):
|
||||||
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(self.homepage)
|
||||||
return self.page.get_rivers_list()
|
return self.page.get_rivers_list()
|
||||||
|
|
||||||
def iter_history(self, sensor):
|
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)
|
return self.page.iter_history(sensor)
|
||||||
|
|
|
||||||
|
|
@ -27,24 +27,28 @@ __all__ = ['ListPage', 'HistoryPage']
|
||||||
|
|
||||||
|
|
||||||
class ListPage(BasePage):
|
class ListPage(BasePage):
|
||||||
alarmlevel = {"as1.gif": u"Alarmstufe 1", "as2.gif": u"Alarmstufe 2", \
|
alarmlevel = {"as1.gif": u"Alarmstufe 1", "as2.gif": u"Alarmstufe 2",
|
||||||
"as3.gif": u"Alarmstufe 3", "as4.gig": u"Alarmstufe 4", \
|
"as3.gif": u"Alarmstufe 3", "as4.gig": u"Alarmstufe 4",
|
||||||
"qua_grau.gif": u"No alarm function", "p_gruen.gif": u"", \
|
"qua_grau.gif": u"No alarm function", "p_gruen.gif": u"",
|
||||||
"qua_weiss.gif": u"no data"}
|
"qua_weiss.gif": u"no data"}
|
||||||
|
|
||||||
def get_rivers_list(self):
|
def get_rivers_list(self):
|
||||||
for pegel in self.document.getroot().xpath(".//a[@onmouseout='pegelaus()']"):
|
for pegel in self.document.getroot().xpath(".//a[@onmouseout='pegelaus()']"):
|
||||||
div = pegel.getparent()
|
div = pegel.getparent()
|
||||||
img = div.find('.//img').attrib['src'].split('/')[1]
|
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 = Gauge(int(data[7]))
|
||||||
gauge.name = unicode(data[0].strip("'"))
|
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])
|
gauge.object = unicode(data[1])
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
try:
|
try:
|
||||||
lastdate = date(*reversed([int(x) for x in data[2].split(' ')[0].split(".")]))
|
lastdate = date(*reversed([int(x)
|
||||||
lasttime = time(*[int(x) for x in data[2].split(' ')[1].split(":")])
|
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)
|
lastdate = datetime.combine(lastdate, lasttime)
|
||||||
except:
|
except:
|
||||||
lastdate = NotAvailable
|
lastdate = NotAvailable
|
||||||
|
|
@ -106,8 +110,10 @@ class HistoryPage(BasePage):
|
||||||
lines.pop(0) # remove first value (already in lastvalue)
|
lines.pop(0) # remove first value (already in lastvalue)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
history = GaugeMeasure()
|
history = GaugeMeasure()
|
||||||
leveldate = date(*reversed([int(x) for x in line[0].text_content().split(' ')[0].split(".")]))
|
leveldate = date(*reversed([int(x)
|
||||||
leveltime = time(*[int(x) for x in line[0].text_content().split(' ')[1].split(":")])
|
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)
|
history.date = datetime.combine(leveldate, leveltime)
|
||||||
|
|
||||||
if sensor.name == u"Level":
|
if sensor.name == u"Level":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue