Commit 56fd9c4e authored by Roger Philibert's avatar Roger Philibert Committed by hydrargyrum
Browse files

backport devel modules fixes

parent b4a38e83
Pipeline #370484182 failed with stages
in 12 minutes and 1 second
......@@ -154,7 +154,7 @@ def check_date(self, obj):
return False
def check_category(self, obj):
return (not self.env['categories'] or obj.category in self.env['categories'])
return not self.env['categories'] or obj.category in self.env['categories']
obj_id = Format('%s.%s',
Env('region'),
......@@ -166,4 +166,4 @@ def obj_start_date(self):
_date = Date(CleanText('./meta[@itemprop="startDate"]/@content'))(self)
return datetime.combine(_date, time.min)
obj_category = AgendaculturelCategory(Regexp(CleanText('./@itemtype'), 'http://schema.org/(.*)'))
obj_category = AgendaculturelCategory(Regexp(CleanText('./@itemtype'), 'https://schema.org/(.*)'))
......@@ -31,7 +31,7 @@ def setUp(self):
self.backend.config['place'] = Value(value='paris')
def test_agendaculturel(self):
l = list(self.backend.list_events(datetime.now()))
assert len(l)
event = self.backend.get_event(l[0].id)
_ = list(self.backend.list_events(datetime.now()))
assert len(_)
event = self.backend.get_event(_[0].id)
self.assertTrue(event.url, 'URL for event "%s" not found: %s' % (event.id, event.url))
......@@ -52,7 +52,8 @@ def obj_start_date(self):
'\w* \w* (\d?\d \w* \d{4}) \w* (\d{2}h\d{2}).*',
'\\1 \\2',
flags=re.UNICODE),
parse_func=parse_french_date)(self)
parse_func=parse_french_date,
strict=False)(self)
def obj_end_date(self):
m = re.findall(r'\w* \w* \d?\d \w* \d{4} \w* \d{2}h\d{2}', CleanText('(//p)[1]')(self), re.UNICODE)
......@@ -62,14 +63,16 @@ def obj_end_date(self):
r'\w* \w* (\d?\d \w* \d{4}) \w* \d{2}h\d{2} \w* (\d{2}h\d{2})',
'\\1 \\2',
flags=re.UNICODE),
parse_func=parse_french_date)(self)
parse_func=parse_french_date,
strict=False)(self)
else:
return DateTime(Regexp(CleanText('(//p)[1]'),
r'\w* \w* (\d?\d \w* \d{4}) \w* (\d{2}h\d{2})',
'\\1 \\2',
nth=-1,
flags=re.UNICODE),
parse_func=parse_french_date)(self)
parse_func=parse_french_date,
strict=False)(self)
class EventListPage(HTMLPage):
......@@ -115,7 +118,8 @@ def obj_start_date(self):
'\w* \w* (\d?\d \w* \d{4}) \w* (\d{2}h\d{2}).*',
'\\1 \\2',
flags=re.UNICODE),
parse_func=parse_french_date)(self)
parse_func=parse_french_date,
strict=False)(self)
def obj_end_date(self):
m = re.findall(r'\w* \w* \d?\d \w* \d{4} \w* \d{2}h\d{2}', CleanText('./@title')(self), re.UNICODE)
......@@ -125,14 +129,16 @@ def obj_end_date(self):
r'\w* \w* (\d?\d \w* \d{4}) \w* \d{2}h\d{2} \w* (\d{2}h\d{2})',
'\\1 \\2',
flags=re.UNICODE),
parse_func=parse_french_date)(self)
parse_func=parse_french_date,
strict=False)(self)
else:
return DateTime(Regexp(CleanText('./@title'),
r'\w* \w* (\d?\d \w* \d{4}) \w* (\d{2}h\d{2})',
'\\1 \\2',
nth=-1,
flags=re.UNICODE),
parse_func=parse_french_date)(self)
parse_func=parse_french_date,
strict=False)(self)
def validate(self, obj):
return (self.is_valid_event(obj, self.env['city'], self.env['categories']) and
......
......@@ -27,8 +27,8 @@
class LameteoagricoleBrowser(PagesBrowser):
BASEURL = 'https://www.lameteoagricole.net'
cities = URL(r'/autocomplete/autocomplete_ajax.php\?table=meteo_communes&field=NomComMaj&search=(?P<pattern>.*)', CitiesPage)
cities = URL(r'/autocomplete/autocomplete_ajax_new.php\?table=meteo_ville_france_new&field=nom_commune_normalise&search=(?P<pattern>.*)',
CitiesPage)
hour = URL(r'/meteo-heure-par-heure/(?P<code>[^.]+).html',
r'/index_meteo-heure-par-heure.php\?communehome=(?P<id>.*)',
HourPage)
......
......@@ -23,12 +23,12 @@
from woob.browser.elements import method, ListElement, ItemElement
from woob.browser.filters.standard import CleanText, Field
from woob.browser.pages import HTMLPage
from woob.browser.pages import HTMLPage, XMLPage
from woob.capabilities.weather import City, Forecast, Temperature, Current, Direction
from woob.tools.compat import quote
class CitiesPage(HTMLPage):
class CitiesPage(XMLPage):
ENCODING = 'utf-8'
@method
......@@ -70,7 +70,7 @@ def fill_base(self, obj, n):
speed_text = self.get_cell(self.titles['Vitesse Moy. du vent'], n)
else:
speed_text = self.get_cell(self.titles['Vitesse moyenne du vent'], n)
obj.wind_speed = int(speed_text.replace('km/h', '').strip())
obj.wind_speed = float(speed_text.replace('km/h', '').strip())
if 'Probabilité de précipitations' in self.titles:
txt = self.get_cell(self.titles['Probabilité de précipitations'], n)
......@@ -86,7 +86,8 @@ def get_cell(self, row, col):
return CleanText('//table[@id="meteoHour"]/tr[{row}]/td[{col}]'.format(row=row + 1, col=col + 1))(self.doc)
def get_img_cell(self, row, col):
return CleanText('//table[@id="meteoHour"]/tr[{row}]/td[{col}]/img/@alt'.format(row=row + 1, col=col + 1))(self.doc)
return CleanText('//table[@id="meteoHour"]/tr[{row}]/td[{col}]/img/@alt'.format(row=row + 1,
col=col + 1))(self.doc)
def get_current(self):
fore = next(iter(self.iter_forecast()))
......@@ -115,7 +116,7 @@ def iter_forecast(self):
day_str = new_day_str
obj.date = datetime.combine(d, t)
obj.low = obj.high = temp(int(self.get_cell(self.titles['T° (ressentie)'], n).split('°')[0]))
obj.low = obj.high = temp(float(self.get_cell(self.titles['T° (ressentie)'], n).split('°')[0]))
self.fill_base(obj, n)
yield obj
......@@ -123,10 +124,13 @@ def iter_forecast(self):
class Days5Page(WeatherPage):
def get_cell(self, row, col):
return CleanText('//table[@id="meteo2"]/tr[2]/td[{col}]/table/tr[{row}]/td'.format(row=row + 1, col=col + 1))(self.doc)
return CleanText('//table[@id="meteo2"]/tr[2]/td[{col}]/table/tr[{row}]/td'.format(row=row + 1,
col=col + 1))(self.doc)
def get_img_cell(self, row, col):
return CleanText('//table[@id="meteo2"]/tr[2]/td[{col}]/table/tr[{row}]/td//img/@alt'.format(row=row + 1, col=col + 1))(self.doc)
return CleanText(
'//table[@id="meteo2"]/tr[2]/td[{col}]/table/tr[{row}]/td//img/@alt'.format(row=row + 1,
col=col + 1))(self.doc)
def iter_forecast(self):
d = date.today()
......@@ -137,11 +141,11 @@ def iter_forecast(self):
for n in range(1, len(self.doc.xpath('//table[@id="meteo2"]/tr[1]/td'))):
obj = Forecast()
obj.low = temp(int(self.get_cell(self.titles['Température Mini'], n).rstrip('°')))
obj.low = temp(float(self.get_cell(self.titles['Température Mini'], n).rstrip('°')))
high_text = self.get_cell(self.titles['Température Maxi'], n).rstrip('°')
if high_text != '-':
obj.high = temp(int(high_text))
obj.high = temp(float(high_text))
obj.date = d
self.fill_base(obj, n)
......@@ -152,10 +156,13 @@ def iter_forecast(self):
class Days10Page(WeatherPage):
def get_cell(self, row, col):
return CleanText('(//table[@id="meteo2"]//td/table)[{col}]/tr[{row}]/td'.format(row=row + 1, col=col + 1))(self.doc)
return CleanText('(//table[@id="meteo2"]//td/table)[{col}]/tr[{row}]/td'.format(row=row + 1,
col=col + 1))(self.doc)
def get_img_cell(self, row, col):
return CleanText('(//table[@id="meteo2"]//td/table)[{col}]/tr[{row}]/td//img/@alt'.format(row=row + 1, col=col + 1))(self.doc)
return CleanText(
'(//table[@id="meteo2"]//td/table)[{col}]/tr[{row}]/td//img/@alt'.format(row=row + 1,
col=col + 1))(self.doc)
def iter_forecast(self):
d = date.today() + timedelta(5)
......@@ -167,8 +174,8 @@ def iter_forecast(self):
cols = len(self.doc.xpath('//table[@id="meteo2"]//td/table'))
for n in range(1, cols):
obj = Forecast()
obj.low = temp(int(self.get_cell(self.titles['Température Mini'], n).rstrip('°C')))
obj.high = temp(int(self.get_cell(self.titles['Température Maxi'], n).rstrip('°C')))
obj.low = temp(float(self.get_cell(self.titles['Température Mini'], n).rstrip('°C')))
obj.high = temp(float(self.get_cell(self.titles['Température Maxi'], n).rstrip('°C')))
obj.date = d
self.fill_base(obj, n)
......
......@@ -33,10 +33,10 @@ def _check_translations(self, src, dst, text):
return [t.text for t in res]
def test_translate(self):
res = self._check_translations('French', 'English', 'maison')
res = self._check_translations('fr', 'en', 'maison')
assert res
assert any(t == 'house' for t in res)
res = self._check_translations('German', 'French', 'kaffee')
res = self._check_translations('de', 'fr', 'kaffee')
assert res
assert any('café' in t for t in res)
......@@ -25,5 +25,5 @@ class WordReferenceTest(BackendTest):
MODULE = 'wordreference'
def test_translate(self):
tr = list(self.backend.translate('French', 'English', 'chat'))[0]
tr = list(self.backend.translate('fr', 'en', 'chat'))[0]
self.assertEqual(tr.text, u'cat')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment