Exemplo n.º 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"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
Exemplo n.º 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"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
Exemplo n.º 3
0
 def _create_attach_sensor(self, value, gauge_id, last_update, adresse):
     levelattach = GaugeSensor(gauge_id + '-attach')
     levelattach.name = u'Attach'
     levelattach.address = u'%s' % adresse
     lastvalue = GaugeMeasure()
     if lastvalue.level < 1:
         lastvalue.alarm = u'Full station'
     lastvalue.level = float(value)
     lastvalue.date = last_update
     levelattach.lastvalue = lastvalue
     levelattach.history = NotLoaded
     levelattach.gaugeid = gauge_id
     return levelattach
Exemplo n.º 4
0
 def _create_bikes_sensor(self, value, gauge_id, last_update, adresse):
     levelbikes = GaugeSensor(gauge_id + '-bikes')
     levelbikes.name = u'Bikes'
     levelbikes.address = u'%s' % adresse
     lastvalue = GaugeMeasure()
     lastvalue.level = float(value)
     lastvalue.date = last_update
     if lastvalue.level < 1:
         lastvalue.alarm = u'Empty station'
     levelbikes.lastvalue = lastvalue
     levelbikes.history = NotLoaded
     levelbikes.gaugeid = gauge_id
     return levelbikes
Exemplo n.º 5
0
 def _create_attach_sensor(self, value, gauge_id, last_update, adresse):
     levelattach = GaugeSensor(gauge_id + '-attach')
     levelattach.name = u'Attach'
     levelattach.address = u'%s' % adresse
     lastvalue = GaugeMeasure()
     if lastvalue.level < 1:
         lastvalue.alarm = u'Full station'
     lastvalue.level = float(value)
     lastvalue.date = last_update
     levelattach.lastvalue = lastvalue
     levelattach.history = NotLoaded
     levelattach.gaugeid = gauge_id
     return levelattach
Exemplo n.º 6
0
 def _create_bikes_sensor(self, value, gauge_id, last_update, adresse):
     levelbikes = GaugeSensor(gauge_id + '-bikes')
     levelbikes.name = u'Bikes'
     levelbikes.address = u'%s' % adresse
     lastvalue = GaugeMeasure()
     lastvalue.level = float(value)
     lastvalue.date = last_update
     if lastvalue.level < 1:
         lastvalue.alarm = u'Empty station'
     levelbikes.lastvalue = lastvalue
     levelbikes.history = NotLoaded
     levelbikes.gaugeid = gauge_id
     return levelbikes
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
        def _create_coef_sensor(self, gauge_id, AM=True):
            name = CleanText('//tr[@class="MJE"]/th[4]')(self)
            _name = 'matin' if AM else 'aprem'
            value = self._get_coef_value(AM=AM)

            if value:
                coef = GaugeSensor(u'%s-%s-%s' % (gauge_id, name, _name))
                coef.name = '%s %s' % (name, _name)
                coef.lastvalue = value
                coef.gaugeid = gauge_id

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

                return coef
Exemplo n.º 10
0
 def _create_status_sensor(self, value, gauge_id, last_update, adresse):
     levelstatus = GaugeSensor(gauge_id + '-status')
     levelstatus.name = u'Status'
     levelstatus.address = u'%s' % adresse
     lastvalue = GaugeMeasure()
     status = float(value)
     if status == 0:
         status = 1
     else:
         status = -1
     if lastvalue.level < 1:
         lastvalue.alarm = u'Not available station'
     lastvalue.level = float(status)
     lastvalue.date = last_update
     levelstatus.lastvalue = lastvalue
     levelstatus.history = NotLoaded
     levelstatus.gaugeid = gauge_id
     return levelstatus
Exemplo n.º 11
0
        def _create_coef_sensor(self, gauge_id, AM=True):
            name = CleanText('//tr[@class="MJE"]/th[4]')(self)
            _name = 'matin' if AM else 'aprem'
            value = self._get_coef_value(AM=AM)

            if value:
                coef = GaugeSensor(u'%s-%s-%s' % (gauge_id, name, _name))
                coef.name = '%s %s' % (name, _name)
                coef.lastvalue = value
                coef.gaugeid = gauge_id

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

                return coef
Exemplo n.º 12
0
 def _create_status_sensor(self, value, gauge_id, last_update, adresse):
     levelstatus = GaugeSensor(gauge_id + '-status')
     levelstatus.name = u'Status'
     levelstatus.address = u'%s' % adresse
     lastvalue = GaugeMeasure()
     status = float(value)
     if status == 0:
         status = 1
     else:
         status = -1
     if lastvalue.level < 1:
         lastvalue.alarm = u'Not available station'
     lastvalue.level = float(status)
     lastvalue.date = last_update
     levelstatus.lastvalue = lastvalue
     levelstatus.history = NotLoaded
     levelstatus.gaugeid = gauge_id
     return levelstatus
Exemplo n.º 13
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
Exemplo n.º 14
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
Exemplo n.º 15
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
Exemplo n.º 16
0
    def get_rivers_list(self):
        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 = unicode(data[0].strip("'"))
            gauge.city = gauge.name.split(' ')[0]  # TODO: real regexp to remove the number
            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])
                levelsensor = GaugeSensor(gauge.id + "-level")
                levelsensor.name = u"Level"
                # TODO levelsensor.unit =
                levelsensor.forecast = forecast
                lastvalue = GaugeMeasure()
                lastvalue.level = level
                lastvalue.date = lastdate
                # TODO lastvalue.alarm =
                levelsensor.lastvalue = lastvalue
                levelsensor.history = NotLoaded
                levelsensor.gaugeid = gauge.id
                sensors.append(levelsensor)
            except:
                pass
            try:
                flow = float(data[4])
                flowsensor = GaugeSensor(gauge.id + "-flow")
                flowsensor.name = u"Flow"
                # TODO flowsensor.unit =
                flowsensor.forecast = forecast
                lastvalue = GaugeMeasure()
                lastvalue.level = flow
                lastvalue.date = lastdate
                # TODO lastvalue.alarm =
                flowsensor.lastvalue = lastvalue
                flowsensor.history = NotLoaded
                flowsensor.gaugeid = gauge.id
                sensors.append(flowsensor)
            except:
                pass

            gauge.sensors = sensors

            yield gauge