From a0b816fe18227a4e241446f910fad8105f5c8b8b Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 26 Apr 2023 23:03:43 +0200 Subject: [PATCH] add debug thread --- import_export_canalblog.py | 19 +++++++++---------- lib/WPExport.py | 14 +++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/import_export_canalblog.py b/import_export_canalblog.py index 8a35d24..e2e8a99 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -168,15 +168,14 @@ if __name__ == '__main__': exportWp.downloadCss() if args.html is False or args.img is False: - ex = futures.ThreadPoolExecutor(max_workers=int(args.parallel)) - #args = [int(args.parallel), exportWp, args.html, args.img] - #f = ex.map(download, args) - #print("wait !!!") - wait_for = [ - ex.submit(download, i, int(args.parallel), url, logger, args.parser, args.directory, args.html, args.img) - for i in range(0, int(args.parallel)) - ] + try: + with futures.ThreadPoolExecutor(max_workers=int(args.parallel)) as ex: + wait_for = [ + ex.submit(download, i, int(args.parallel), url, logger, args.parser, args.directory, args.html, args.img) + for i in range(0, int(args.parallel)) + ] + except Exception as err: + logger.error("Threading error : {0}".format(err)) - #for i in range(0, int(args.parallel)): - # threading.Thread(name="Thread-{0}".format(i + 1), target=download, args=(i, 3, exportWp,args.html, args.img)).start() + exit(0) \ No newline at end of file diff --git a/lib/WPExport.py b/lib/WPExport.py index 957a234..7cf709c 100644 --- a/lib/WPExport.py +++ b/lib/WPExport.py @@ -150,7 +150,7 @@ class WPExport: makedir.append(i) repath = "/".join(makedir) if not os.path.exists(repath): - self._logger.debug("Dossier crée : {0}".format(repath)) + self._logger.debug("{0} : Dossier crée : {1}".format(self._name, repath)) try: if len(repath) > 0: os.mkdir(repath) @@ -216,21 +216,21 @@ class WPExport: try: page = self._request.get(i) except Exception as err: - self._logger.error("Connection error : {0}".format(err)) + self._logger.error("{0} : Connection error : {1}".format(self._name, err)) exit(1) if page.status_code == 200: soup = BeautifulSoup(page.text, self._parser) img = soup.find_all("img") - self._logger.info("image from page: {0} : ".format(i)) + self._logger.info("{0} : image from page: {1} : ".format(self._name,i)) for anchor in img: src = anchor.get("src", "/") if src != "/": if src not in page_img: - self._logger.info("image: {0} : ".format(src)) + self._logger.info("{0} : image: {1} : ".format(self._name, src)) page_img.append(src) else: - self._logger.error("Image did not get due status code : {0}".format(page.status_code)) - self._logger.debug(page.content) + self._logger.error("{0} : Image did not get due status code : {1}".format(self._name, page.status_code)) + self._logger.debug("{0} : {1}".format(self._name, page.content)) return page_img @@ -258,7 +258,7 @@ class WPExport: fileDownload = "{0}/{1}/index.html".format(backup_dir, o.netloc) if len(dir_page_web) > 0 and len(filePageWeb) > 0: fileDownload = "{0}/{1}{2}/{3}".format(backup_dir, o.netloc, dir_page_web, filePageWeb) - self._logger.info("{0}/{1} : {2}".format(i+1, len(webpage), fileDownload)) + self._logger.info("{0} : {1}/{2} : {3}".format(self._name, i+1, len(webpage), fileDownload)) try: open(fileDownload, "wb").write(r.content) except Exception as err: