Skip to content
Extraits de code Groupes Projets
Valider c77517b7 rédigé par Bastien Le Querrec's avatar Bastien Le Querrec
Parcourir les fichiers

prefdpt: détecte automatiquement la présence d'un lien vers un RAA

parent d5cb33ce
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -12,4 +12,3 @@ class Attrap_pref06(Attrap_prefdpt):
# Configuration des widgets à analyser
Attrap_prefdpt.grey_card['regex']['year'] = 'Année *([0-9]{4})'
Attrap_prefdpt.white_card['link_to_raa'] = True
......@@ -16,7 +16,6 @@ class Attrap_pref10(Attrap_prefdpt):
# Configuration des widgets à analyser
Attrap_prefdpt.grey_card['regex']['year'] = 'RAA *([0-9]{4})'
Attrap_prefdpt.white_card['link_to_raa'] = True
# On ajoute un widget custom représentant les liens sur la page d'accueil
Attrap_prefdpt.widgets.append(
......
......@@ -20,6 +20,7 @@ class Attrap_prefdpt(Attrap):
'title': 'div.fr-card.fr-card--sm.fr-card--grey.fr-enlarge-link div.fr-card__body div.fr-card__content h2.fr-card__title a'
},
'link_to_raa': False,
'autodetect_links_to_raa': True,
'follow_link_on_unrecognised_date': True
}
white_card = {
......@@ -33,6 +34,7 @@ class Attrap_prefdpt(Attrap):
'pager': 'ul.fr-pagination__list li a.fr-pagination__link.fr-pagination__link--next.fr-pagination__link--lg-label' # Chemin CSS du pager des cartes blanches
},
'link_to_raa': False,
'autodetect_links_to_raa': True,
'follow_link_on_unrecognised_date': True
}
......@@ -52,11 +54,12 @@ class Attrap_prefdpt(Attrap):
class DptWidget:
"""Une classe représentant un widget sur le site d'une préfecture de département."""
def __init__(self, name, regex=None, css_path=None, link_to_raa=False, follow_link_on_unrecognised_date=True):
def __init__(self, name, regex=None, css_path=None, link_to_raa=False, autodetect_links_to_raa=True, follow_link_on_unrecognised_date=True):
self.name = name
self.regex = regex
self.css_path = css_path
self.link_to_raa = link_to_raa
self.autodetect_links_to_raa = autodetect_links_to_raa
self.follow_link_on_unrecognised_date = follow_link_on_unrecognised_date
def has_css_path(self, key):
......@@ -96,6 +99,7 @@ class Attrap_prefdpt(Attrap):
regex=self.grey_card['regex'],
css_path=self.grey_card['css_path'],
link_to_raa=self.grey_card['link_to_raa'],
autodetect_links_to_raa=self.grey_card['autodetect_links_to_raa'],
follow_link_on_unrecognised_date=self.grey_card['follow_link_on_unrecognised_date']
)
)
......@@ -107,6 +111,7 @@ class Attrap_prefdpt(Attrap):
regex=self.white_card['regex'],
css_path=self.white_card['css_path'],
link_to_raa=self.white_card['link_to_raa'],
autodetect_links_to_raa=self.white_card['autodetect_links_to_raa'],
follow_link_on_unrecognised_date=self.white_card['follow_link_on_unrecognised_date']
)
)
......@@ -171,7 +176,7 @@ class Attrap_prefdpt(Attrap):
date = datetime.datetime(9999, 1, 1)
# Si la configuration indique que les liens renvoient vers un RAA, on ajoute le lien à la liste des éléments
if widget.link_to_raa:
if widget.link_to_raa or (widget.autodetect_links_to_raa and card['url'].endswith('.pdf')):
if date.year == 9999:
date = None
raa = Attrap.RAA(card['url'], date, card['name'].strip(), timezone=self.timezone)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter