velib: add longitude,latitude coordinates attributes to sensors

This commit is contained in:
Vincent A 2013-11-05 09:52:18 +01:00 committed by Florent
commit 60dc02e30f
2 changed files with 12 additions and 1 deletions

View file

@ -19,6 +19,7 @@
from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.capabilities.base import StringField
from weboob.capabilities.gauge import ICapGauge, GaugeSensor, Gauge, GaugeMeasure, SensorNotFound
from weboob.tools.value import Value
@ -43,6 +44,11 @@ class BikeMeasure(GaugeMeasure):
return '<GaugeMeasure level=%d>' % self.level
class BikeSensor(GaugeSensor):
longitude = StringField('Longitude of the sensor')
latitude = StringField('Latitude of the sensor')
class VelibBackend(BaseBackend, ICapGauge):
NAME = 'velib'
DESCRIPTION = (u'City bike renting availability information.\nCities: %s' %
@ -71,10 +77,12 @@ class VelibBackend(BaseBackend, ICapGauge):
def _make_sensor(self, sensor_type, info, gauge):
id = '%s.%s' % (sensor_type, gauge.id)
sensor = GaugeSensor(id)
sensor = BikeSensor(id)
sensor.gaugeid = gauge.id
sensor.name = SENSOR_TYPES[sensor_type]
sensor.address = unicode(info['address'])
sensor.longitude = info['longitude']
sensor.latitude = info['latitude']
sensor.history = []
return sensor

View file

@ -63,4 +63,7 @@ class VelibBrowser(BaseBrowser):
jgauge['id'] = '%s.%s' % (jgauge['number'], jgauge['contract_name'])
jgauge['city'] = jgauge['contract_name']
jgauge['last_update'] = datetime.datetime.fromtimestamp(jgauge['last_update'] / 1000)
jgauge['latitude'] = str(jgauge['position']['lat'])
jgauge['longitude'] = str(jgauge['position']['lng'])
del jgauge['position']
return jgauge