From c5070717b93dc52ce08081a550b7cc6a285299d1 Mon Sep 17 00:00:00 2001
From: Bastien Le Querrec <blq@laquadrature.net>
Date: Tue, 7 Jan 2025 12:54:46 +0100
Subject: [PATCH] pref39: utilise prefdpt

---
 Attrap_pref39.py | 63 +++++-------------------------------------------
 1 file changed, 6 insertions(+), 57 deletions(-)

diff --git a/Attrap_pref39.py b/Attrap_pref39.py
index c1cdc59..9f4ae76 100644
--- a/Attrap_pref39.py
+++ b/Attrap_pref39.py
@@ -1,66 +1,15 @@
-import os
-import datetime
+from Attrap_prefdpt import Attrap_prefdpt
 
-from bs4 import BeautifulSoup
-from urllib.parse import unquote
 
-from Attrap import Attrap
+class Attrap_pref39(Attrap_prefdpt):
 
-
-class Attrap_pref39(Attrap):
-
-    # Config
+    # Configuration de la préfecture
     hostname = "https://www.jura.gouv.fr"
     raa_page = f'{hostname}/Publications/Publications-legales/Recueil-des-Actes-Administratifs'
-    user_agent = 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
     full_name = "Préfecture du Jura"
     short_code = "pref39"
     timezone = 'Europe/Paris'
 
-    def __init__(self, data_dir):
-        super().__init__(data_dir, self.user_agent)
-        self.set_sleep_time(30)
-
-    def get_raa(self, keywords):
-        # On récupère les pages d'années
-        year_pages = []
-        page_content = self.get_page(self.raa_page, 'get').content
-        for card in self.get_sub_pages(
-            page_content,
-            'div.fr-card__body div.fr-card__content h2.fr-card__title a',
-            self.hostname,
-            False
-        ):
-            if Attrap.guess_date(card['name'], '.* ([0-9]{4})').year >= self.not_before.year:
-                year_pages.append(card['url'])
-
-        # On récupère tous les RAA en suivant la navigation
-        elements = self.get_raa_with_pager(
-            year_pages,
-            'a.fr-pagination__link.fr-pagination__link--next',
-            self.hostname
-        )
-
-        self.parse_raa(elements, keywords)
-        self.mailer()
-
-    def get_raa_elements(self, page_content):
-        elements = []
-        # On charge le parser
-        soup = BeautifulSoup(page_content, 'html.parser')
-
-        # Pour chaque balise a, on regarde si c'est un PDF, et si oui on le parse
-        for a in soup.select('.fr-card__title a.fr-card__link.menu-item-link'):
-            if a.get('href') and a['href'].endswith('.pdf'):
-                if a['href'].startswith('/'):
-                    url = f"{self.hostname}{a['href']}"
-                else:
-                    url = a['href']
-
-                url = unquote(url)
-                name = a.get_text().strip()
-                date = datetime.datetime.strptime(a['title'].split(' - ')[-1].strip(), '%d/%m/%Y')
-
-                raa = Attrap.RAA(url, date, name, timezone=self.timezone)
-                elements.append(raa)
-        return elements
+    # Configuration des widgets à analyser
+    Attrap_prefdpt.grey_card['regex']['year'] = 'Année ([0-9]{4})'
+    #Attrap_prefdpt.white_card['css_path']['details'] = None
-- 
GitLab