From d88ae7ed44a665b198d7d3af6ddc0f04feef261f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 23 Aug 2023 22:48:38 +0200 Subject: [PATCH] add author --- import_export_canalblog.py | 19 ++++++++++--------- lib/WPImport.py | 13 ++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/import_export_canalblog.py b/import_export_canalblog.py index cb6ea4f..246953e 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -67,7 +67,7 @@ def download(name_thread, max_thread, url, logger, parser, directory, html, img, del exportWp -def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, basic, serial, ssl_wordpress, ssl_canalblog, create, update, image, revert, tmp): +def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, basic, serial, ssl_wordpress, ssl_canalblog, create, update, image, revert, tmp, author): canalblog = canalblog.split(",") wordpress = wordpress.split(",") name = "Thread-{0}".format(int(name_thread) + 1) @@ -88,7 +88,7 @@ def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, bas exportWp.getUrlPage(name_thread, max_thread) del exportWp for j in wordpress: - importWp = WPimport(name=name, basic=basic, wordpress=j, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp) + importWp = WPimport(name=name, basic=basic, wordpress=j, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp, author=author) for k in ["article", "page"]: for l in ["publications", "principal"]: importWp.fromUrl(l, k) @@ -110,7 +110,7 @@ def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, bas if not revert: exportWp.getUrlPage(name_thread, max_thread) del exportWp - importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp) + importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp, author=author) for k in ["article", "page"]: for l in ["publications", "principal"]: @@ -119,13 +119,13 @@ def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, bas del importWp -def importDirectory(name_thread, max_thread, directory, logger, parser, wordpress, basic, serial, ssl_wordpress, create, update, image, revert): +def importDirectory(name_thread, max_thread, directory, logger, parser, wordpress, basic, serial, ssl_wordpress, create, update, image, revert, author): name = "Thread-{0}".format(int(name_thread) + 1) directory = directory.split(",") wordpress = wordpress.split(",") if serial is False: for i in wordpress: - importWp = WPimport(name=name, basic=basic, wordpress=i, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image) + importWp = WPimport(name=name, basic=basic, wordpress=i, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, author=author) for j in directory: importWp.fromDirectory(j, name_thread, max_thread, revert) del importWp @@ -135,7 +135,7 @@ def importDirectory(name_thread, max_thread, directory, logger, parser, wordpres logger.error("{0} : Error : Number directory is different than wordpress".format(name)) exit(1) for i in range(0, len(wordpress)-1): - importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image) + importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, author=author) importWp.fromDirectory(directory[i], name_thread, max_thread, revert) del importWp @@ -170,6 +170,7 @@ if __name__ == '__main__': import_parser.add_argument("--no-create", help="No create post", dest="create", default="store_false", action="store_true") import_parser.add_argument("--no-update", help="No update post", dest="update", default="store_false", action="store_true") import_parser.add_argument("--no-image", help="No image add or update", dest="image", default="store_false", action="store_true") + import_parser.add_argument("--author", help="Define author for page album", default="") @@ -264,7 +265,7 @@ if __name__ == '__main__': importWp.setUrl(i) importWp.fromFile(files=args.file.split(",")) exit(0) - menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress) + menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress, author=args.author) menuWp.fromFile("{0}".format(args.file.split(",")[0])) if len(args.directory) > 0: try: @@ -273,7 +274,7 @@ if __name__ == '__main__': wait(wait_for, return_when=ALL_COMPLETED) errorRevert(logger, args.revert, args.tmp) wait_for = [ - ex.submit(importDirectory, i, int(args.parallel), args.directory, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, args.create, args.update, args.image, args.revert) + ex.submit(importDirectory, i, int(args.parallel), args.directory, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, args.create, args.update, args.image, args.revert, args.author) for i in range(0, int(args.parallel)) ] wait(wait_for, return_when=ALL_COMPLETED) @@ -288,7 +289,7 @@ if __name__ == '__main__': wait(wait_for, return_when=ALL_COMPLETED) errorRevert(logger, args.revert, args.tmp) wait_for = [ - ex.submit(importUrl, i, int(args.parallel), args.canalblog, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, ssl_canalblog, args.create, args.update, args.image, args.revert, args.tmp) + ex.submit(importUrl, i, int(args.parallel), args.canalblog, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, ssl_canalblog, args.create, args.update, args.image, args.revert, args.tmp, args.author) for i in range(0, int(args.parallel)) ] wait(wait_for, return_when=ALL_COMPLETED) diff --git a/lib/WPImport.py b/lib/WPImport.py index 2f1dc61..36969d6 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -8,7 +8,7 @@ from requests.packages.urllib3.util.retry import Retry class WPimport: # Constructor - def __init__(self, name="Thread-0", basic=None, wordpress="", logger=None, parser="html.parser", ssl_wordpress=True, no_create=False, no_update=False, no_image=False, tmp="/tmp/import_export_canablog"): + def __init__(self, name="Thread-0", basic=None, wordpress="", logger=None, parser="html.parser", ssl_wordpress=True, no_create=False, no_update=False, no_image=False, tmp="/tmp/import_export_canablog", author=""): self._name = name self._basic = basic self._wordpress = wordpress @@ -29,6 +29,7 @@ class WPimport: self._no_update = no_update self._no_image = no_image self._tmp = tmp + self._author = author # Destructor def __del__(self): @@ -131,10 +132,10 @@ class WPimport: new_img = {} href_img = i.get("src") href_img_o = urlparse(href_img) - new_img["old_src"]=href_img try: if len(href_img_o.netloc) > 0: img_ok = False + href_img = href_img.replace("_q", "_o") page_img = self._request.get(href_img) if page_img.status_code == 200: img_ok = True @@ -158,14 +159,12 @@ class WPimport: content_html = "" if len(list_img) > 0: - content_html = "

{0}

\n\n".format(albumdesc) + content_html = "\n{0}\n\n\n".format(albumdesc) - content_html = content_html + "