add parameter parser

This commit is contained in:
Valentin CZERYBA 2023-04-09 21:17:49 +02:00
parent 7e484fa308
commit cd6b03b0ff
2 changed files with 5 additions and 3 deletions

View File

@ -6,10 +6,11 @@ import requests, os, logging, re, json
class WPimport: class WPimport:
# Constructor # Constructor
def __init__(self, basic, wordpress, logger): def __init__(self, basic, wordpress, logger, parser):
self._basic = basic self._basic = basic
self._wordpress = wordpress self._wordpress = wordpress
self._logger = logger self._logger = logger
self._parser = parser
# Public method # Public method
@ -26,7 +27,7 @@ class WPimport:
self._logger.info("Fichier en cours de traitement : {0}".format(file)) self._logger.info("Fichier en cours de traitement : {0}".format(file))
with open(file, 'r') as f: with open(file, 'r') as f:
content = f.read() content = f.read()
soup = BeautifulSoup(content, 'html.parser') soup = BeautifulSoup(content, self._parser)
articlebody = soup.find_all("div", class_="articlebody") articlebody = soup.find_all("div", class_="articlebody")
if len(articlebody) > 0: if len(articlebody) > 0:
self._addOrUpdatePost(soup) self._addOrUpdatePost(soup)

View File

@ -10,6 +10,7 @@ if __name__ == '__main__':
parser.add_argument("--debug", help="Verbosity", action="store_true") parser.add_argument("--debug", help="Verbosity", action="store_true")
parser.add_argument("--logfile", help="Log file", default="") parser.add_argument("--logfile", help="Log file", default="")
parser.add_argument("--quiet", help="No console output", action="store_true") 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") subparsers = parser.add_subparsers(dest="command")
@ -65,7 +66,7 @@ if __name__ == '__main__':
exit(1) exit(1)
basic = HTTPBasicAuth(args.user, password) 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: if len(args.file) > 0:
importWp.fromFile(args.file.split(",")) importWp.fromFile(args.file.split(","))
exit(0) exit(0)