From 16368c13bb04437570f22f47f1ea733d3ef8e0db Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 10 Jun 2023 01:58:08 +0200 Subject: [PATCH] add WPChange --- import_export_canalblog.py | 30 +++++++++++++++++++++++++++++- lib/WPChange.py | 5 ++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/import_export_canalblog.py b/import_export_canalblog.py index c14d9f7..418df05 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -9,6 +9,13 @@ import argparse, logging, threading from lib.WPImport import WPimport from lib.WPExport import WPExport from lib.WPRemove import WPRemove +from lib.WPChange import WPChange + +def change(index, number, args, logger): + changeWp = WPChange(logger=logger, index_name=index, number_thread=number) + changeWp.fromDirectory(args.directory) + + del changeWp def remove(index, number, args, basic, logger, ssl_wordpress): removeWp = WPRemove(basic=basic, wordpress="", logger=logger, ssl_wordpress=ssl_wordpress, index_name=index, number_thread=number) @@ -172,7 +179,15 @@ if __name__ == '__main__': export_parser.add_argument("--no-img", help="No img", dest="img", action="store_true") export_parser.add_argument("--no-html", help="No HTML", dest="html", action="store_true") - + change_parser = subparsers.add_parser("change") + change_parser.add_argument("--directory", + default="", + help="Directory") + change_parser.add_argument("--file", + default="", + help="File") + + args = parser.parse_args() @@ -293,4 +308,17 @@ if __name__ == '__main__': wait_for = [ ex.submit(remove, i, args.parallel, args, basic, logger, ssl_wordpress) for i in range(0, int(args.parallel)) ] except Exception as err: logger.error("Thread error for remove : {0}".format(err)) + exit(0) + + if args.command == "change": + if len(args.directory) > 0: + try: + with futures.ThreadPoolExecutor(max_workers=int(args.parallel)) as ex: + wait_for = [ ex.submit(change, i, args.parallel, args, logger) for i in range(0, int(args.parallel)) ] + except Exception as err: + logger.error("Thread error for remove : {0}".format(err)) + if len(args.file) > 0: + changeWp = WPChange(logger=logger) + for filei in args.file.split(","): + changeWp.fromFile(filei) exit(0) \ No newline at end of file diff --git a/lib/WPChange.py b/lib/WPChange.py index b6e7b05..255e9c1 100644 --- a/lib/WPChange.py +++ b/lib/WPChange.py @@ -2,7 +2,7 @@ from bs4 import BeautifulSoup from urllib.parse import urlparse import requests, os, logging, re, json -class WPRemove: +class WPChange: # Constructor def __init__(self, index_name=1, number_thread=1, logger=None, parser="html.parser"): self._name = "Thread-{0}".format(index_name) @@ -76,5 +76,8 @@ class WPRemove: content = f.read() soup = BeautifulSoup(content, self._parser) img = soup.find_all("img") + for i in img: + src = i.get("src") + self._logger.info(src)