add WPChange

This commit is contained in:
Valentin CZERYBA 2023-06-10 01:58:08 +02:00
parent c631909cb6
commit 16368c13bb
2 changed files with 33 additions and 2 deletions

View File

@ -9,6 +9,13 @@ import argparse, logging, threading
from lib.WPImport import WPimport from lib.WPImport import WPimport
from lib.WPExport import WPExport from lib.WPExport import WPExport
from lib.WPRemove import WPRemove 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): 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) removeWp = WPRemove(basic=basic, wordpress="", logger=logger, ssl_wordpress=ssl_wordpress, index_name=index, number_thread=number)
@ -172,6 +179,14 @@ if __name__ == '__main__':
export_parser.add_argument("--no-img", help="No img", dest="img", action="store_true") 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") 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() args = parser.parse_args()
@ -294,3 +309,16 @@ if __name__ == '__main__':
except Exception as err: except Exception as err:
logger.error("Thread error for remove : {0}".format(err)) logger.error("Thread error for remove : {0}".format(err))
exit(0) 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)

View File

@ -2,7 +2,7 @@ from bs4 import BeautifulSoup
from urllib.parse import urlparse from urllib.parse import urlparse
import requests, os, logging, re, json import requests, os, logging, re, json
class WPRemove: class WPChange:
# Constructor # Constructor
def __init__(self, index_name=1, number_thread=1, logger=None, parser="html.parser"): def __init__(self, index_name=1, number_thread=1, logger=None, parser="html.parser"):
self._name = "Thread-{0}".format(index_name) self._name = "Thread-{0}".format(index_name)
@ -76,5 +76,8 @@ class WPRemove:
content = f.read() content = f.read()
soup = BeautifulSoup(content, self._parser) soup = BeautifulSoup(content, self._parser)
img = soup.find_all("img") img = soup.find_all("img")
for i in img:
src = i.get("src")
self._logger.info(src)