From d712fb9ed73046fc51804c78fa0b9907c3731362 Mon Sep 17 00:00:00 2001 From: Bastien Le Querrec <blq@laquadrature.net> Date: Sat, 18 Jan 2025 15:33:34 +0100 Subject: [PATCH] =?UTF-8?q?prefdpt:=20la=20date=20calcul=C3=A9e=20dans=20u?= =?UTF-8?q?n=20select=20peut=20ne=20contenir=20que=20l'ann=C3=A9e=20ou=20l?= =?UTF-8?q?e=20mois=20et=20l'ann=C3=A9e=20seulement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Attrap_pref35.py | 3 ++- Attrap_pref38.py | 3 ++- Attrap_pref54.py | 3 ++- Attrap_pref77.py | 3 ++- Attrap_prefdpt.py | 12 ++++++++++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Attrap_pref35.py b/Attrap_pref35.py index 202bbf0..e5be5a8 100644 --- a/Attrap_pref35.py +++ b/Attrap_pref35.py @@ -19,6 +19,7 @@ class Attrap_pref35(Attrap_prefdpt): Attrap_prefdpt.DptSelectWidget( 'menu_deroulant', regex=year_regex, - css_path='div.fr-select-group select#Archives-des-RAA-liste-docs.fr-select' + css_path='div.fr-select-group select#Archives-des-RAA-liste-docs.fr-select', + type='year' ) ) diff --git a/Attrap_pref38.py b/Attrap_pref38.py index b040921..7d11be3 100644 --- a/Attrap_pref38.py +++ b/Attrap_pref38.py @@ -21,6 +21,7 @@ class Attrap_pref38(Attrap_prefdpt): Attrap_prefdpt.DptSelectWidget( 'menu_deroulant', regex='([0-9]{1,2}[er]{0,1} [a-zéû]* [0-9]{4})', - css_path='select#-liste-docs' + css_path='select#-liste-docs', + type='year-month-day' ) ) diff --git a/Attrap_pref54.py b/Attrap_pref54.py index 48d84b4..dedc95d 100644 --- a/Attrap_pref54.py +++ b/Attrap_pref54.py @@ -18,6 +18,7 @@ class Attrap_pref54(Attrap_prefdpt): Attrap_prefdpt.DptSelectWidget( 'menu_deroulant', regex='.* du ([0-9]*(?:er|ER)? [A-Za-zéÉûÛ]* [0-9]*)', - css_path='select#Liste-liste-docs' + css_path='select#Liste-liste-docs', + type='year-month-day' ) ) diff --git a/Attrap_pref77.py b/Attrap_pref77.py index 5caeb99..e67b77e 100644 --- a/Attrap_pref77.py +++ b/Attrap_pref77.py @@ -18,6 +18,7 @@ class Attrap_pref77(Attrap_prefdpt): Attrap_prefdpt.DptSelectWidget( 'menu_deroulant', regex='D77-([0-9]{2}-[0-9]{2}-[0-9]{4})', - css_path='select#Liste-liste-docs' + css_path='select#Liste-liste-docs', + type='year-month-day' ) ) diff --git a/Attrap_prefdpt.py b/Attrap_prefdpt.py index de0c3e3..907c23c 100644 --- a/Attrap_prefdpt.py +++ b/Attrap_prefdpt.py @@ -90,12 +90,13 @@ class Attrap_prefdpt(Attrap): class DptSelectWidget: """Une classe représentant un menu déroulant sur le site d'une préfecture de département.""" - def __init__(self, name, regex=None, css_path=None, follow_link_on_unrecognised_date=True, exclude=[]): + def __init__(self, name, regex=None, css_path=None, follow_link_on_unrecognised_date=True, exclude=[], type='year-month-day'): self.name = name self.regex = regex self.css_path = css_path self.follow_link_on_unrecognised_date = follow_link_on_unrecognised_date self.exclude = exclude + self.type = type def add_url(self, url, date=None): if date and date.year == 9999: @@ -243,10 +244,17 @@ class Attrap_prefdpt(Attrap): if not option['value'] == "" and option['title'].strip() not in select_widget.exclude: # On estime la date à partir du nom de fichier date = Attrap.guess_date(option['title'].strip(), select_widget.regex) + match select_widget.type: + case 'year': + date = date.replace(day=1, month=1) + not_before = self.not_before.replace(day=1, month=1) + case 'year-month': + date = date.replace(day=1) + not_before = self.not_before.replace(day=1) # Si la date estimée correspond à la plage d'analyse ou si follow_link_on_unrecognised_date est à True, # on demande au serveur les détails du RAA - if (date.year < 9999 and date >= self.not_before) or (date.year == 9999 and select_widget.follow_link_on_unrecognised_date): + if (date.year < 9999 and date >= not_before) or (date.year == 9999 and select_widget.follow_link_on_unrecognised_date): page_content = self.get_page( page_url[0], 'post', -- GitLab