From cd6b03b0ffbb592e619ea74485f6d9b68dcd5d8e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 9 Apr 2023 21:17:49 +0200 Subject: [PATCH] add parameter parser --- WPImport.py | 5 +++-- import_export_canalblog.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/WPImport.py b/WPImport.py index e3164f1..92f6681 100644 --- a/WPImport.py +++ b/WPImport.py @@ -6,10 +6,11 @@ import requests, os, logging, re, json class WPimport: # Constructor - def __init__(self, basic, wordpress, logger): + def __init__(self, basic, wordpress, logger, parser): self._basic = basic self._wordpress = wordpress self._logger = logger + self._parser = parser # Public method @@ -26,7 +27,7 @@ class WPimport: self._logger.info("Fichier en cours de traitement : {0}".format(file)) with open(file, 'r') as f: content = f.read() - soup = BeautifulSoup(content, 'html.parser') + soup = BeautifulSoup(content, self._parser) articlebody = soup.find_all("div", class_="articlebody") if len(articlebody) > 0: self._addOrUpdatePost(soup) diff --git a/import_export_canalblog.py b/import_export_canalblog.py index 7e5ea30..cc19a06 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -10,6 +10,7 @@ if __name__ == '__main__': parser.add_argument("--debug", help="Verbosity", action="store_true") parser.add_argument("--logfile", help="Log file", default="") parser.add_argument("--quiet", help="No console output", action="store_true") + parser.add_argument("--parser", help="Parser content", default="html.parser") subparsers = parser.add_subparsers(dest="command") @@ -65,7 +66,7 @@ if __name__ == '__main__': exit(1) basic = HTTPBasicAuth(args.user, password) - importWp = WPImport.WPimport(basic, args.wordpress, logger) + importWp = WPImport.WPimport(basic, args.wordpress, logger, args.parser) if len(args.file) > 0: importWp.fromFile(args.file.split(",")) exit(0)