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

pref65: détecte l'URL de l'année voulue automatiquement

parent 39d9e8af
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -11,14 +11,7 @@ class Attrap_pref65(Attrap):
# Config
__HOST = 'https://www.hautes-pyrenees.gouv.fr'
__RAA_PAGE = {
'2024': f'{__HOST}/Publications/Recueil-d-actes-administratifs/RAA-2024',
'2023': f'{__HOST}/Publications/Recueil-d-actes-administratifs/RAA-2023',
'2022': f'{__HOST}/Publications/Recueil-d-actes-administratifs/RAA-2022',
'2021': f'{__HOST}/Publications/Recueil-d-actes-administratifs/RAA-2021',
'2020': f'{__HOST}/Publications/Recueil-d-actes-administratifs/RAA-2020',
'2019': f'{__HOST}/Publications/Recueil-d-actes-administratifs/RAA-2019'
}
__RAA_PAGE = f'{__HOST}/Publications/Recueil-d-actes-administratifs'
__USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
full_name = 'Préfecture des Hautes-Pyrénées'
short_code = 'pref65'
......@@ -28,19 +21,18 @@ class Attrap_pref65(Attrap):
self.set_sleep_time(30)
def get_raa(self, keywords):
# On détermine quelles pages d'année parser
pages_to_parse = []
if self.not_before.year <= 2024:
pages_to_parse.append(self.__RAA_PAGE['2024'])
if self.not_before.year <= 2023:
pages_to_parse.append(self.__RAA_PAGE['2023'])
if self.not_before.year <= 2022:
pages_to_parse.append(self.__RAA_PAGE['2022'])
if self.not_before.year <= 2021:
pages_to_parse.append(self.__RAA_PAGE['2021'])
if self.not_before.year <= 2020:
pages_to_parse.append(self.__RAA_PAGE['2020'])
if self.not_before.year <= 2019:
pages_to_parse.append(self.__RAA_PAGE['2019'])
year_pages = self.get_sub_pages_with_pager(
self.__RAA_PAGE,
'div.fr-card.fr-card--horizontal.fr-card--sm.fr-enlarge-link.fr-mb-3w div.fr-card__body div.fr-card__content h2.fr-card__title a.fr-card__link',
'ul.fr-pagination__list li a.fr-pagination__link.fr-pagination__link--next.fr-pagination__link--lg-label',
'div.fr-card.fr-card--horizontal.fr-card--sm.fr-enlarge-link.fr-mb-3w div.fr-card__body div.fr-card__content div.fr-card__end p.fr-card__detail',
self.__HOST
)
for year_page in year_pages:
if Attrap.guess_date(year_page['name'].strip(), '.*([0-9]{4})').year >= self.not_before.year:
pages_to_parse.append(year_page['url'])
elements = []
for raa_page in pages_to_parse:
......
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