From d6d09f29b4a6caaea68375c9e1464f9d332134dd Mon Sep 17 00:00:00 2001 From: Bastien Le Querrec <blq@laquadrature.net> Date: Sat, 13 Apr 2024 23:28:15 +0200 Subject: [PATCH] =?UTF-8?q?cli:=20par=20d=C3=A9faut,=20aucun=20mot-cl?= =?UTF-8?q?=C3=A9=20n'est=20recherch=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RAAspotter.py | 51 ++++++++++++++++++++++--------------------- RAAspotter_ppparis.py | 2 +- RAAspotter_pref04.py | 2 +- RAAspotter_pref05.py | 2 +- RAAspotter_pref06.py | 2 +- RAAspotter_pref09.py | 2 +- RAAspotter_pref13.py | 2 +- RAAspotter_pref31.py | 2 +- RAAspotter_pref33.py | 2 +- RAAspotter_pref34.py | 2 +- RAAspotter_pref35.py | 2 +- RAAspotter_pref38.py | 2 +- RAAspotter_pref42.py | 2 +- RAAspotter_pref44.py | 2 +- RAAspotter_pref59.py | 2 +- RAAspotter_pref62.py | 2 +- RAAspotter_pref64.py | 2 +- RAAspotter_pref65.py | 2 +- RAAspotter_pref66.py | 2 +- RAAspotter_pref69.py | 2 +- RAAspotter_pref80.py | 2 +- RAAspotter_pref81.py | 2 +- RAAspotter_pref83.py | 2 +- RAAspotter_pref87.py | 2 +- RAAspotter_pref976.py | 2 +- cli.py | 5 ++--- 26 files changed, 52 insertions(+), 52 deletions(-) diff --git a/RAAspotter.py b/RAAspotter.py index 06624fb..30611c1 100644 --- a/RAAspotter.py +++ b/RAAspotter.py @@ -460,31 +460,32 @@ class RAAspotter: writer.write(f'{self.data_dir}/raa/{raa.get_sha256()}.flat.pdf') def search_keywords(self, raa, keywords): - text = open(f'{self.data_dir}/raa/{raa.get_sha256()}.txt').read() - - found = False - found_keywords = [] - for keyword in keywords: - if re.search(keyword, text, re.IGNORECASE | re.MULTILINE): - if not found: - url = quote(raa.url, safe='/:') - self.print_output(f'\033[92m{raa.name}\033[0m ({raa.date_str})') - self.print_output(f'URL : {url}') - found = True - self.found = True - self.print_output(f' Le terme \033[1m{keyword}\033[0m a été trouvé.') - found_keywords.append(keyword) - - if found: - self.print_output('') - url = quote(raa.url, safe='/:') - found_keywords_str = ', '.join( - [str(x) for x in found_keywords] - ) - self.mastodon_toot( - f'{raa.name} ({raa.date_str})\n\nLes termes suivants ont ' - f'été trouvés : {found_keywords_str}.\n\nURL : {url}' - ) + if keywords and not keywords == '': + text = open(f'{self.data_dir}/raa/{raa.get_sha256()}.txt').read() + + found = False + found_keywords = [] + for keyword in keywords.split(','): + if re.search(keyword, text, re.IGNORECASE | re.MULTILINE): + if not found: + url = quote(raa.url, safe='/:') + self.print_output(f'\033[92m{raa.name}\033[0m ({raa.date_str})') + self.print_output(f'URL : {url}') + found = True + self.found = True + self.print_output(f' Le terme \033[1m{keyword}\033[0m a été trouvé.') + found_keywords.append(keyword) + + if found: + self.print_output('') + url = quote(raa.url, safe='/:') + found_keywords_str = ', '.join( + [str(x) for x in found_keywords] + ) + self.mastodon_toot( + f'{raa.name} ({raa.date_str})\n\nLes termes suivants ont ' + f'été trouvés : {found_keywords_str}.\n\nURL : {url}' + ) def parse_raa(self, elements, keywords): for raa in elements: diff --git a/RAAspotter_ppparis.py b/RAAspotter_ppparis.py index c7981d4..360e0dd 100644 --- a/RAAspotter_ppparis.py +++ b/RAAspotter_ppparis.py @@ -26,7 +26,7 @@ class RAAspotter_ppparis(RAAspotter): page_content = self.get_session(self.__RAA_PAGE, self.__WAIT_ELEMENT, 3) raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref04.py b/RAAspotter_pref04.py index 2a16978..d73c1bf 100644 --- a/RAAspotter_pref04.py +++ b/RAAspotter_pref04.py @@ -36,7 +36,7 @@ class RAAspotter_pref04(RAAspotter): if RAAspotter.guess_date(sub_page['name'], '([0-9]{4}).*').year >= self.not_before.year: sub_page_content = self.get_page(sub_page['url'], 'get').content raa_elements = self.get_raa_elements(sub_page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() diff --git a/RAAspotter_pref05.py b/RAAspotter_pref05.py index 1bfa6f8..57c419c 100644 --- a/RAAspotter_pref05.py +++ b/RAAspotter_pref05.py @@ -78,7 +78,7 @@ class RAAspotter_pref05(RAAspotter): elements.append(element) # On parse les RAA - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref06.py b/RAAspotter_pref06.py index 0210da9..46f05ff 100644 --- a/RAAspotter_pref06.py +++ b/RAAspotter_pref06.py @@ -81,7 +81,7 @@ class RAAspotter_pref06(RAAspotter): ".fr-pagination__link.fr-pagination__link--next", self.__HOST ) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref09.py b/RAAspotter_pref09.py index 20b395c..4c4f68b 100644 --- a/RAAspotter_pref09.py +++ b/RAAspotter_pref09.py @@ -48,7 +48,7 @@ class RAAspotter_pref09(RAAspotter): for page in pages_to_parse: page_content = self.get_page(page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref13.py b/RAAspotter_pref13.py index 17ca16e..4be6d73 100644 --- a/RAAspotter_pref13.py +++ b/RAAspotter_pref13.py @@ -35,7 +35,7 @@ class RAAspotter_pref13(RAAspotter): for raa_page in self.__RAA_PAGE: page_content = self.get_page(raa_page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() diff --git a/RAAspotter_pref31.py b/RAAspotter_pref31.py index 7e3e72e..c612bf8 100644 --- a/RAAspotter_pref31.py +++ b/RAAspotter_pref31.py @@ -50,7 +50,7 @@ class RAAspotter_pref31(RAAspotter): ): elements.append(element) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref33.py b/RAAspotter_pref33.py index e68827c..d7d0458 100644 --- a/RAAspotter_pref33.py +++ b/RAAspotter_pref33.py @@ -79,7 +79,7 @@ class RAAspotter_pref33(RAAspotter): self.__HOST )[::-1] - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref34.py b/RAAspotter_pref34.py index d905e4b..1cf5b86 100644 --- a/RAAspotter_pref34.py +++ b/RAAspotter_pref34.py @@ -49,7 +49,7 @@ class RAAspotter_pref34(RAAspotter): for raa_page in pages_to_parse: page_content = self.get_page(raa_page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() diff --git a/RAAspotter_pref35.py b/RAAspotter_pref35.py index 469215c..d2f5bda 100644 --- a/RAAspotter_pref35.py +++ b/RAAspotter_pref35.py @@ -35,7 +35,7 @@ class RAAspotter_pref35(RAAspotter): for raa_page in self.__RAA_PAGE: page_content = self.get_page(raa_page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() diff --git a/RAAspotter_pref38.py b/RAAspotter_pref38.py index 22e0f9f..39e0656 100644 --- a/RAAspotter_pref38.py +++ b/RAAspotter_pref38.py @@ -52,7 +52,7 @@ class RAAspotter_pref38(RAAspotter): for raa_page in pages_to_parse: page_content = self.get_page(raa_page, 'get').content raa_elements = self.get_raa_elements(page_content, raa_page) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() def get_raa_elements(self, page_content, raa_page): diff --git a/RAAspotter_pref42.py b/RAAspotter_pref42.py index 7e24629..ae1ea7f 100644 --- a/RAAspotter_pref42.py +++ b/RAAspotter_pref42.py @@ -57,7 +57,7 @@ class RAAspotter_pref42(RAAspotter): elements.append(element) # On parse les RAA - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref44.py b/RAAspotter_pref44.py index 49ad13d..96cf356 100644 --- a/RAAspotter_pref44.py +++ b/RAAspotter_pref44.py @@ -79,7 +79,7 @@ class RAAspotter_pref44(RAAspotter): self.__HOST )[::-1] - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref59.py b/RAAspotter_pref59.py index e911a7e..956aa61 100644 --- a/RAAspotter_pref59.py +++ b/RAAspotter_pref59.py @@ -61,7 +61,7 @@ class RAAspotter_pref59(RAAspotter): for sub_page in sub_pages[::-1]: sub_page_content = self.get_page(sub_page['url'], 'get').content sub_raa_elements = self.get_raa_elements(sub_page_content) - self.parse_raa(sub_raa_elements, keywords.split(',')) + self.parse_raa(sub_raa_elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref62.py b/RAAspotter_pref62.py index 3f64ccc..d542d57 100644 --- a/RAAspotter_pref62.py +++ b/RAAspotter_pref62.py @@ -72,7 +72,7 @@ class RAAspotter_pref62(RAAspotter): for raa_page in pages_to_parse: page_content = self.get_page(raa_page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref64.py b/RAAspotter_pref64.py index adacb30..404d1dc 100644 --- a/RAAspotter_pref64.py +++ b/RAAspotter_pref64.py @@ -80,7 +80,7 @@ class RAAspotter_pref64(RAAspotter): for raa in self.get_raa_elements(page_content): elements.append(raa) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref65.py b/RAAspotter_pref65.py index 68278d2..99d3c99 100644 --- a/RAAspotter_pref65.py +++ b/RAAspotter_pref65.py @@ -49,7 +49,7 @@ class RAAspotter_pref65(RAAspotter): for raa_page in pages_to_parse: page_content = self.get_page(raa_page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() diff --git a/RAAspotter_pref66.py b/RAAspotter_pref66.py index 6ffde9b..3bf4406 100644 --- a/RAAspotter_pref66.py +++ b/RAAspotter_pref66.py @@ -66,7 +66,7 @@ class RAAspotter_pref66(RAAspotter): for element in self.get_raa_elements_before_2024(self.__RAA_PAGE['2019']): elements.append(element) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() # On parse un lien d'avant 2024 diff --git a/RAAspotter_pref69.py b/RAAspotter_pref69.py index e28a831..0d6be9a 100644 --- a/RAAspotter_pref69.py +++ b/RAAspotter_pref69.py @@ -64,7 +64,7 @@ class RAAspotter_pref69(RAAspotter): for element in self.get_raa_elements(page_content)[::-1]: elements.append(element) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref80.py b/RAAspotter_pref80.py index b616fd1..03b4c27 100644 --- a/RAAspotter_pref80.py +++ b/RAAspotter_pref80.py @@ -56,7 +56,7 @@ class RAAspotter_pref80(RAAspotter): for element in self.get_raa_elements(page_content): elements.append(element) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref81.py b/RAAspotter_pref81.py index 2f4bf7f..c909a70 100644 --- a/RAAspotter_pref81.py +++ b/RAAspotter_pref81.py @@ -77,7 +77,7 @@ class RAAspotter_pref81(RAAspotter): for page in sub_pages_to_parse: page_content = self.get_page(page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() diff --git a/RAAspotter_pref83.py b/RAAspotter_pref83.py index fe73b4f..39b7c17 100644 --- a/RAAspotter_pref83.py +++ b/RAAspotter_pref83.py @@ -67,7 +67,7 @@ class RAAspotter_pref83(RAAspotter): '.fr-pagination__link.fr-pagination__link--next', self.__HOST ) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() diff --git a/RAAspotter_pref87.py b/RAAspotter_pref87.py index 6436659..4e814b4 100644 --- a/RAAspotter_pref87.py +++ b/RAAspotter_pref87.py @@ -85,7 +85,7 @@ class RAAspotter_pref87(RAAspotter): for raa in self.get_raa_elements(page_content): elements.append(raa) - self.parse_raa(elements, keywords.split(',')) + self.parse_raa(elements, keywords) self.mailer() def get_raa_elements(self, page_content): diff --git a/RAAspotter_pref976.py b/RAAspotter_pref976.py index 5d17bb0..cfceb60 100644 --- a/RAAspotter_pref976.py +++ b/RAAspotter_pref976.py @@ -77,7 +77,7 @@ class RAAspotter_pref976(RAAspotter): for page in sub_pages_to_parse: page_content = self.get_page(page, 'get').content raa_elements = self.get_raa_elements(page_content) - self.parse_raa(raa_elements, keywords.split(',')) + self.parse_raa(raa_elements, keywords) self.mailer() def find_raa_card(self, page, year=None): diff --git a/cli.py b/cli.py index 2f959d3..1b038a1 100755 --- a/cli.py +++ b/cli.py @@ -7,8 +7,7 @@ import importlib from RAAspotter import RAAspotter # Config -__KEYWORDS = os.getenv('KEYWORDS') or \ - 'vidéoprotection,caméras,captation,aéronef' +__KEYWORDS = os.getenv('KEYWORDS') or '' __DATA_DIR_ROOT = os.path.dirname(os.path.abspath(__file__)) + '/data/' __SMTP_HOSTNAME = os.getenv('SMTP_HOSTNAME') or 'localhost' __SMTP_USERNAME = os.getenv('SMTP_USERNAME') or '' @@ -81,7 +80,7 @@ parser.add_argument( '-k', '--keywords', action='store', - help='liste des termes recherchés, séparés par une virgule (par défaut : vidéoprotection,caméras,captation,aéronef)' + help='liste des termes recherchés, séparés par une virgule (aucun par défaut)' ) parser.add_argument( '--not-before', -- GitLab