Пример #1
0
 def get_sensors_list(self):
     paraphs = self.document.xpath('//p[@align="center"]')
     sensors = []
     for i in range(len(paraphs)):
         sensor = GaugeSensor("dd-%s" % self.name[i].lower())
         sensor.name = self.name[i]
         sensor.unit = self.unit[i]
         sensor.forecast = NotAvailable
         sensor.history = NotAvailable
         sensor.gaugeid = u"wetter"
         paraph = paraphs[i]
         lastvalue = GaugeMeasure()
         lastvalue.alarm = NotAvailable
         if i == 0:
             text = paraph.xpath('b/span/font[@size="4"]')[1].text
             lastvalue.level = float(text.split('\n')[1].split(u'°')[0])
         if i == 1:
             text = paraph.xpath('b/span/font')[2].text
             lastvalue.level = float(text.split('\n')[1])
         if i == 2:
             text = paraph.xpath('span/font/b')[0].text
             lastvalue.level = float(text.split('\n')[2].split('hPa')[0])
         if i == 3:
             text = paraph.xpath('span/font[@size="4"]/b')[0].text
             lastvalue.level = float(text.split('\n')[2].split(u'%')[0]
                     .split(':')[1])
         if i == 4:
             text = paraph.xpath('b/font[@size="4"]/span')[0].text
             lastvalue.level = float(text.split('\n')[0])
         if i == 5:
             text = paraph.xpath('b/font/span')[0].text
             lastvalue.level = float(text.split('\n')[1])
         sensor.lastvalue = lastvalue
         sensors.append(sensor)
     return sensors
Пример #2
0
 def get_sensors_list(self):
     paraphs = self.document.xpath('//p[@align="center"]')
     sensors = []
     for i in range(len(paraphs)):
         sensor = GaugeSensor("dd-%s" % self.name[i].lower())
         sensor.name = self.name[i]
         sensor.unit = self.unit[i]
         sensor.forecast = NotAvailable
         sensor.history = NotAvailable
         sensor.gaugeid = u"private-dresden"
         paraph = paraphs[i]
         lastvalue = GaugeMeasure()
         lastvalue.alarm = NotAvailable
         if i == 0:
             text = paraph.xpath('b/span/font[@size="4"]')[1].text
             lastvalue.level = float(text.split('\n')[1].split(u'°')[0])
         if i == 1:
             text = paraph.xpath('b/span/font')[2].text
             lastvalue.level = float(text.split('\n')[1])
         if i == 2:
             text = paraph.xpath('span/font/b')[0].text
             lastvalue.level = float(text.split('\n')[2].split('hPa')[0])
         if i == 3:
             text = paraph.xpath('span/font[@size="4"]/b')[0].text
             lastvalue.level = float(text.split('\n')[2].split(u'%')[0]
                     .split(':')[1])
         if i == 4:
             text = paraph.xpath('b/font[@size="4"]/span')[0].text
             lastvalue.level = float(text.split('\n')[0])
         if i == 5:
             text = paraph.xpath('b/font/span')[0].text
             lastvalue.level = float(text.split('\n')[1])
         sensor.lastvalue = lastvalue
         sensors.append(sensor)
     return sensors
Пример #3
0
            def add_sensor(self, sensors, name, unit, value, forecast, alarm, date):
                sensor = GaugeSensor("%s-%s" % (self.obj.id, name.lower()))
                sensor.name = name
                sensor.unit = unit
                sensor.forecast = forecast
                lastvalue = GaugeMeasure()
                lastvalue.alarm = alarm
                try:
                    lastvalue.level = float(value)
                except ValueError:
                    lastvalue.level = NotAvailable
                lastvalue.date = date
                sensor.lastvalue = lastvalue
                sensor.history = NotLoaded
                sensor.gaugeid = self.obj.id

                sensors.append(sensor)
Пример #4
0
            def add_sensor(self, sensors, name, unit, value, forecast, alarm, date):
                sensor = GaugeSensor("%s-%s" % (self.obj.id, name.lower()))
                sensor.name = name
                sensor.unit = unit
                sensor.forecast = forecast
                lastvalue = GaugeMeasure()
                lastvalue.alarm = alarm
                try:
                    lastvalue.level = float(value)
                except ValueError:
                    lastvalue.level = NotAvailable
                lastvalue.date = date
                sensor.lastvalue = lastvalue
                sensor.history = NotLoaded
                sensor.gaugeid = self.obj.id

                sensors.append(sensor)
Пример #5
0
        def _create_high_tide(self, gauge_id, AM=True):
            name = CleanText('//tr[@class="MJE"]/th[3]')(self)
            _name = 'matin' if AM else 'aprem'
            value = self._get_high_tide_value(AM=AM)

            if value:
                tide = GaugeSensor(u'%s-%s-PM-%s' % (gauge_id, name, _name))
                tide.name = u'Pleine Mer %s' % (_name)
                tide.unit = u'm'
                tide.lastvalue = value
                tide.gaugeid = gauge_id

                tide.history = []
                for jour in range(0, 7):
                    measure = self._get_high_tide_value(AM=AM, jour=jour)
                    if measure:
                        tide.history.append(measure)

                return tide
Пример #6
0
        def _create_high_tide(self, gauge_id, AM=True):
            name = CleanText('//tr[@class="MJE"]/th[3]')(self)
            _name = 'matin' if AM else 'aprem'
            value = self._get_high_tide_value(AM=AM)

            if value:
                tide = GaugeSensor(u'%s-%s-PM-%s' % (gauge_id, name, _name))
                tide.name = u'Pleine Mer %s' % (_name)
                tide.unit = u'm'
                tide.lastvalue = value
                tide.gaugeid = gauge_id

                tide.history = []
                for jour in range(0, 7):
                    measure = self._get_high_tide_value(AM=AM, jour=jour)
                    if measure:
                        tide.history.append(measure)

                return tide
Пример #7
0
    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("',")
            gauge = Gauge(int(data[7]))
            gauge.name = unicode(data[0].strip("'"))
            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 = datetime.combine(lastdate, lasttime)
            except:
                lastdate = NotAvailable

            bildforecast = data[5]
            if bildforecast == "pf_gerade.png":
                forecast = u"stable"
            elif bildforecast == "pf_unten.png":
                forecast = u"Go down"
            elif bildforecast == "pf_oben.png":
                forecast = u"Go up"
            else:
                forecast = NotAvailable

            try:
                level = float(data[3])
            except:
                level = NotAvailable
            levelsensor = GaugeSensor(gauge.id + "-level")
            levelsensor.name = u"Level"
            levelsensor.unit = u"cm"
            levelsensor.forecast = forecast
            lastvalue = GaugeMeasure()
            lastvalue.level = level
            lastvalue.date = lastdate
            try:
                lastvalue.alarm = self.alarmlevel[img]
            except KeyError:
                lastvalue.alarm = u""
            levelsensor.lastvalue = lastvalue
            levelsensor.history = NotLoaded
            levelsensor.gaugeid = gauge.id
            sensors.append(levelsensor)

            try:
                flow = float(data[4])
            except:
                flow = NotAvailable
            flowsensor = GaugeSensor(gauge.id + "-flow")
            flowsensor.name = u"Flow"
            flowsensor.unit = u"m3/s"
            flowsensor.forecast = forecast
            lastvalue = GaugeMeasure()
            lastvalue.level = flow
            lastvalue.date = lastdate
            try:
                lastvalue.alarm = self.alarmlevel[img]
            except KeyError:
                lastvalue.alarm = u""
            flowsensor.lastvalue = lastvalue
            flowsensor.history = NotLoaded
            flowsensor.gaugeid = gauge.id
            sensors.append(flowsensor)

            gauge.sensors = sensors

            yield gauge