From 05a3a28c6fd12724985b1c24cde625d6e18cd21d Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 10 Apr 2023 16:36:49 +0200 Subject: [PATCH] add serial for url --- import_export_canalblog.py | 60 +++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/import_export_canalblog.py b/import_export_canalblog.py index 3a6c748..785fbfd 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -21,6 +21,8 @@ if __name__ == '__main__': import_parser.add_argument("--directory", help="HTML directory", default="") import_parser.add_argument("--canalblog", help="URL Canalblog", default="") import_parser.add_argument("--wordpress", help="URL Wordpress", required=True) + import_parser.add_argument("--serial", help="Serial execution", action="store_true") + export_parser = subparsers.add_parser("export") @@ -76,24 +78,56 @@ if __name__ == '__main__': importWp.fromFile(args.file.split(",")) exit(0) if len(args.directory) > 0: - for i in wordpress: - importWp.setUrl(i) - importWp.fromDirectory(args.directory) + directory = args.directory.split(",") + if args.serial is False: + for i in wordpress: + importWp.setUrl(i) + for j in directory: + importWp.fromDirectory(j) + else: + if len(directory) != len(wordpress): + logger.error("ERREUR : Le nombre de dossier n'est pas equivalent au nombre d'URL wordpress") + exit(1) + for i in range(0, len(wordpress)-1): + importWp.setUrl(wordpress[i]) + importWp.fromDirectory(directory[i]) exit(0) if len(args.canalblog) > 0: exportWp = WPExport.WPExport("", logger, args.parser, args.directory) canalblog = args.canalblog.split(",") - for canal in canalblog: - try: - o = urlparse(canal) - o = o._replace(scheme="https") - url = o.geturl().replace(":///", "://") - except Exception as err: - logger.error("parsing error : {0}".format(err)) + wordpress = args.wordpress.split(",") + + if serial is False: + for canal in canalblog: + try: + o = urlparse(canal) + o = o._replace(scheme="https") + url = o.geturl().replace(":///", "://") + except Exception as err: + logger.error("parsing error : {0}".format(err)) + exit(1) + exportWp.setUrl(url) + webpage = exportWp.getUrlPage() + for j in wordpress: + importWp.setUrl(j) + importWp.fromUrl(webpage) + else: + if len(canalblog) != len(wordpress): + logger.error("ERREUR : Le nombre de dossier n'est pas equivalent au nombre d'URL wordpress") exit(1) - exportWp.setUrl(url) - webpage = exportWp.getUrlPage() - importWp.fromUrl(webpage) + for i in range(0, len(canalblog)-1): + try: + o = urlparse(canalblog[i]) + o = o._replace(scheme="https") + url = o.geturl().replace(":///", "://") + except Exception as err: + logger.error("parsing error : {0}".format(err)) + exit(1) + exportWp.setUrl(url) + webpage = exportWp.getUrlPage() + importWp.setUrl(wordpress[i]) + importWp.fromUrl(webpage) + if args.command == "export":