pax_global_header 0000666 0000000 0000000 00000000064 14042356110 0014506 g ustar 00root root 0000000 0000000 52 comment=18d41565f955028f9fcd2f6cc437f5f1cb717401
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/ 0000775 0000000 0000000 00000000000 14042356110 0022744 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/ 0000775 0000000 0000000 00000000000 14042356110 0024414 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/mareeinfo/ 0000775 0000000 0000000 00000000000 14042356110 0026361 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/mareeinfo/__init__.py 0000664 0000000 0000000 00000001505 14042356110 0030473 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2014 Bezleputh
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this woob module. If not, see .
from .module import MareeinfoModule
__all__ = ['MareeinfoModule']
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/mareeinfo/browser.py 0000664 0000000 0000000 00000002255 14042356110 0030422 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2014 Bezleputh
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this woob module. If not, see .
from woob.browser import PagesBrowser, URL
from .pages import IndexPage
class MareeinfoBrowser(PagesBrowser):
BASEURL = 'http://maree.info'
harbor_page = URL('', '(?P<_id>.*)', IndexPage)
def get_harbor_list(self, pattern):
return self.harbor_page.go().get_harbor_list(pattern=pattern)
def get_harbor_infos(self, gauge):
return self.harbor_page.go(_id=gauge.id).get_harbor_infos(obj=gauge)
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/mareeinfo/favicon.png 0000664 0000000 0000000 00000001033 14042356110 0030511 0 ustar 00root root 0000000 0000000 PNG
IHDR @ @ iq gAMA a pHYs (J tEXtSoftware paint.net 4.0.3P IDATx^A Ѿg4F?L!;ĀAyRm؟qhIOG5Z-"O
-6h@G
}B%ݩJ.YNUz4tBwңKS
}BБmh4|DiѰ#JU
4̖f
5h@*pd[EhixvIZx>)MEjfv)`KUj4pT[z-8dk]Dn# IENDB` woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/mareeinfo/module.py 0000664 0000000 0000000 00000004631 14042356110 0030224 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2014 Bezleputh
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this woob module. If not, see .
from woob.tools.backend import Module
from woob.capabilities.base import find_object
from woob.capabilities.gauge import CapGauge, Gauge, SensorNotFound
from .browser import MareeinfoBrowser
__all__ = ['MareeinfoModule']
class MareeinfoModule(Module, CapGauge):
NAME = 'mareeinfo'
DESCRIPTION = u'Un module qui permet d\' aller a la pêche aux moules totalement informé'
MAINTAINER = u'Bezleputh'
EMAIL = 'carton_ben@yahoo.fr'
LICENSE = 'AGPLv3+'
VERSION = '3.1'
BROWSER = MareeinfoBrowser
def get_last_measure(self, sensor_id):
gauge_id = sensor_id.split('-')[0]
return find_object(self.iter_sensors(gauge_id), id=sensor_id, error=SensorNotFound).lastvalue
def iter_gauge_history(self, sensor_id):
gauge_id = sensor_id.split('-')[0]
return find_object(self.iter_sensors(gauge_id), id=sensor_id, error=SensorNotFound).history
def iter_gauges(self, pattern=None):
for _gauge in self.browser.get_harbor_list(pattern):
if pattern is not None:
gauge = self.browser.get_harbor_infos(_gauge)
yield gauge
else:
yield _gauge
def iter_sensors(self, gauge, pattern=None):
if not isinstance(gauge, Gauge):
gauge = find_object(self.iter_gauges(), id=gauge, error=SensorNotFound)
gauge = self.browser.get_harbor_infos(gauge)
if pattern is None:
for sensor in gauge.sensors:
yield sensor
else:
lowpattern = pattern.lower()
for sensor in gauge.sensors:
if lowpattern in sensor.name.lower():
yield sensor
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/mareeinfo/pages.py 0000664 0000000 0000000 00000021042 14042356110 0030031 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2014 Bezleputh
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this woob module. If not, see .
from woob.browser.pages import HTMLPage
from woob.browser.elements import ListElement, ItemElement, method
from woob.browser.filters.standard import CleanText, DateTime, CleanDecimal, Regexp
from woob.browser.filters.html import Link, XPath
from woob.capabilities.gauge import Gauge, GaugeMeasure, GaugeSensor
from datetime import timedelta
import re
class IndexPage(HTMLPage):
@method
class get_harbor_list(ListElement):
item_xpath = "//a[@class='Port PP'] | //a[@class='Port PS']"
class item(ItemElement):
klass = Gauge
obj_id = CleanText(Link('.'), replace=[('/', '')])
obj_name = CleanText('.')
obj_city = CleanText('.')
obj_object = u'Port'
def validate(self, obj):
if self.env['pattern']:
return self.env['pattern'].lower() in obj.name.lower()
return True
@method
class get_harbor_infos(ItemElement):
klass = Gauge
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
def _get_coef_value(self, AM=True, jour=0):
if AM:
time = DateTime(CleanText('//tr[@id="MareeJours_%s"]/td[1]/b[1]' % jour), strict=False)(self)
value = CleanText('//tr[@id="MareeJours_%s"]/td[3]/b[1]' % jour)(self)
else:
time, value = None, None
if len(XPath('//tr[@id="MareeJours_%s"]/td[1]/b' % jour)(self)) > 1:
time = DateTime(CleanText('//tr[@id="MareeJours_%s"]/td[1]/b[2]' % jour), strict=False)(self)
value = CleanText('//tr[@id="MareeJours_%s"]/td[3]/b[2]' % jour)(self)
if time and value:
measure = GaugeMeasure()
measure.level = float(value)
measure.date = time + timedelta(days=jour)
return measure
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
def _get_high_tide_value(self, AM=True, jour=0):
if AM:
time = DateTime(CleanText('//tr[@id="MareeJours_%s"]/td[1]/b[1]' % jour), strict=False)(self)
value = CleanDecimal('//tr[@id="MareeJours_0"]/td[2]/b[1]', replace_dots=True)(self)
else:
time, value = None, None
if len(XPath('//tr[@id="MareeJours_%s"]/td[1]/b' % jour)(self)) > 1:
time = DateTime(CleanText('//tr[@id="MareeJours_%s"]/td[1]/b[2]' % jour),
strict=False, default=None)(self)
value = CleanDecimal('//tr[@id="MareeJours_0"]/td[2]/b[2]', replace_dots=True,
default=None)(self)
if time and value:
measure = GaugeMeasure()
measure.level = float(value)
measure.date = time + timedelta(days=jour)
return measure
def _create_low_tide(self, gauge_id, AM=True):
name = CleanText('//tr[@class="MJE"]/th[3]')(self)
_name = 'matin' if AM else 'aprem'
value = self._get_low_tide_value(AM=AM)
if value:
tide = GaugeSensor(u'%s-%s-BM-%s' % (gauge_id, name, _name))
tide.name = u'Basse 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_low_tide_value(AM=AM, jour=jour)
if measure:
tide.history.append(measure)
return tide
def _is_low_tide_first(self, jour):
return list(XPath('//tr[@id="MareeJours_%s"]/td[1]' % jour)(self)[0])[0].tag != 'b'
def _get_low_tide_value(self, AM=True, jour=0):
slow_tide_pos = 1 if self._is_low_tide_first(jour) else 2
m = re.findall('(\d{2}h\d{2})', CleanText('//tr[@id="MareeJours_%s"]/td[1]' % jour)(self))
re_time = '(\d{2}h\d{2}).*(\d{2}h\d{2}).*(\d{2}h\d{2})'
re_value = '(.*)m(.*)m(.*)m'
if len(m) > 3:
re_time = '(\d{2}h\d{2}).*(\d{2}h\d{2}).*(\d{2}h\d{2}).*(\d{2}h\d{2})'
re_value = '(.*)m(.*)m(.*)m(.*)m'
if AM:
time = DateTime(Regexp(CleanText('//tr[@id="MareeJours_%s"]/td[1]' % jour),
re_time,
'\\%s' % slow_tide_pos), strict=False)(self)
value = CleanDecimal(Regexp(CleanText('//tr[@id="MareeJours_%s"]/td[2]' % jour),
re_value,
'\\%s' % slow_tide_pos),
replace_dots=True, default=None)(self)
else:
slow_tide_pos += 2
time, value = None, None
if len(m) > slow_tide_pos - 1:
time = DateTime(Regexp(CleanText('//tr[@id="MareeJours_%s"]/td[1]' % jour),
re_time,
'\\%s' % slow_tide_pos), strict=False)(self)
value = CleanDecimal(Regexp(CleanText('//tr[@id="MareeJours_%s"]/td[2]' % jour),
re_value,
'\\%s' % slow_tide_pos),
replace_dots=True, default=None)(self)
if time and value:
measure = GaugeMeasure()
measure.level = float(value)
measure.date = time + timedelta(days=jour)
return measure
def obj_sensors(self):
sensors = []
high_tide_PM = self._create_high_tide(self.obj.id)
if high_tide_PM:
sensors.append(high_tide_PM)
high_tide_AM = self._create_high_tide(self.obj.id, AM=False)
if high_tide_AM:
sensors.append(high_tide_AM)
low_tide_AM = self._create_low_tide(self.obj.id)
if low_tide_AM:
sensors.append(low_tide_AM)
low_tide_PM = self._create_low_tide(self.obj.id, AM=False)
if low_tide_PM:
sensors.append(low_tide_PM)
coef_AM = self._create_coef_sensor(self.obj.id)
if coef_AM:
sensors.append(coef_AM)
coef_PM = self._create_coef_sensor(self.obj.id, AM=False)
if coef_PM:
sensors.append(coef_PM)
return sensors
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-mareeinfo/modules/mareeinfo/test.py 0000664 0000000 0000000 00000002365 14042356110 0027720 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2014 Bezleputh
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this woob module. If not, see .
from woob.tools.test import BackendTest
class MareeinfoTest(BackendTest):
MODULE = 'mareeinfo'
def test_mareeinfo(self):
l = list(self.backend.iter_gauges())
self.assertTrue(len(l) > 0)
gauge = l[0]
s = list(self.backend.iter_sensors(gauge))
self.assertTrue(len(s) > 0)
sensor = s[0]
self.assertTrue(self.backend.get_last_measure(sensor.id) is not None)
self.assertTrue(len(self.backend.iter_gauge_history(sensor.id)) > 0)