From c085eda39af9ea2e0d87e3e4c8d475d4c713b7a9 Mon Sep 17 00:00:00 2001 From: Hadrien <ketsapiwiq@protonmail.com> Date: Sun, 9 Jun 2024 22:48:54 +0200 Subject: [PATCH] =?UTF-8?q?pref45:=20ajout=20de=20la=20pr=C3=A9fecture=20d?= =?UTF-8?q?u=20Loiret?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ajout loiret format --- .gitlab-ci.yml | 5 +++ Attrap_pref45.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + cli.py | 1 + 4 files changed, 87 insertions(+) create mode 100644 Attrap_pref45.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2fb196d..312a1fd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -214,6 +214,11 @@ test_pref44: PREF: "pref44" extends: .default_pref +test_pref45: + variables: + PREF: "pref45" + extends: .default_pref + test_pref49: variables: PREF: "pref49" diff --git a/Attrap_pref45.py b/Attrap_pref45.py new file mode 100644 index 0000000..31c22f5 --- /dev/null +++ b/Attrap_pref45.py @@ -0,0 +1,80 @@ +import os +import datetime + +from bs4 import BeautifulSoup +from urllib.parse import unquote + +from Attrap import Attrap + + +class Attrap_pref45(Attrap): + months_fr = [ + "Janvier", + "Fevrier", + "Mars", + "Avril", + "Mai", + "Juin", + "Juillet", + "Aout", + "Septembre", + "Octobre", + "Novembre", + "Decembre", + ] + __RAA_PAGE = {} + # Config + __HOST = "https://www.loiret.gouv.fr" + + __USER_AGENT = ( + "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0" + ) + full_name = "Préfecture du Loiret" + short_code = "pref45" + + def __init__(self, data_dir): + super().__init__(data_dir, self.__USER_AGENT) + self.enable_tor(10) + + def get_raa(self, keywords): + + for year in range(self.not_before.year, 2026): + self.__RAA_PAGE[str(year)] = [] + for month in self.months_fr: + self.__RAA_PAGE[str(year)].append( + f"{self.__HOST}/Publications/Recueil-des-actes-administratifs/Recueil-des-actes-administratifs-departementaux/{year}/{month}-{year}" + ) + elements = [] + for year in self.__RAA_PAGE: + for page in self.__RAA_PAGE[year]: + print(page) + page_content = self.get_page(page, "get").content + for raa in self.get_raa_elements(page_content): + elements.append(raa) + + self.parse_raa(elements, keywords) + self.mailer() + + def get_raa_elements(self, page_content): + elements = [] + + soup = BeautifulSoup(page_content, "html.parser") + + for a in soup.select("a.fr-link.fr-link--download"): + if a.get("href") and a["href"].endswith(".pdf"): + if a["href"].startswith("/"): + url = f"{self.__HOST}{a['href']}" + else: + url = a["href"] + + url = unquote(url) + name = ( + a.find("span").previous_sibling.replace("Télécharger ", "").strip() + ) + date = datetime.datetime.strptime( + a.find("span").get_text().split(" - ")[-1].strip(), "%d/%m/%Y" + ) + + raa = Attrap.RAA(url, date, name) + elements.append(raa) + return elements diff --git a/README.md b/README.md index 6638e3f..036f2a6 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Vous pouvez également activer le safe mode en spécifiant la variable d'environ - Préfecture du Jura (identifiant : `pref39`) - Préfecture de la Loire (identifiant : `pref42`) - Préfecture de la Loire-Atlantique (identifiant : `pref44`) +- Préfecture du Loiret (identifiant : `pref45`) - Préfecture de Maine-et-Loire (identifiant : `pref49`) - Préfecture de la Manche (identifiant : `pref50`) - Préfecture de la Haute-Marne (identifiant : `pref52`) diff --git a/cli.py b/cli.py index 421ce0d..8bb3b1e 100755 --- a/cli.py +++ b/cli.py @@ -68,6 +68,7 @@ available_administrations = [ 'pref39', 'pref42', 'pref44', + 'pref45', 'pref49', 'pref50', 'pref52', -- GitLab