From 1f7e442d04c1e8092a708e2cc12e4ad1606d5efb Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 6 Apr 2023 21:53:56 +0200 Subject: [PATCH] wip directory --- insert_wordpress.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/insert_wordpress.py b/insert_wordpress.py index 2c3828e..c91964b 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -13,6 +13,13 @@ class WPimport: # Public method + def fromDirectory(self, directory): + directory = "{0}/archives".format(directory) + for item in os.listdir(directory): + subdirectory = self._checkDirectory(item) + print(subdirectory) + + def fromFile(self, files): for file in files.split(","): if os.path.exists(file): @@ -27,6 +34,11 @@ class WPimport: # Private method + def _checkDirectory(self, item): + if os.path.isdir(item): + self._checkDirectory(item) + return item + ## Add or update featured media def _addOrUpdateFeaturedMedia(self, soup): @@ -243,7 +255,8 @@ class WPimport: if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("--user", help="wordpress user", required=True) - parser.add_argument("--file", help="HTML file", required=True) + parser.add_argument("--file", help="HTML file", default="") + parser.add_argument("--directory", help="HTML directory", default="") parser.add_argument("--wordpress", help="URL Wordpress", required=True) args = parser.parse_args() password = getpass() @@ -253,4 +266,8 @@ if __name__ == '__main__': basic = HTTPBasicAuth(args.user, password) importWp = WPimport(basic, args.wordpress) - importWp.fromFile(args.file) \ No newline at end of file + if len(args.file) > 0: + importWp.fromFile(args.file) + exit(0) + if len(args.directory) > 0: + importWp.fromDirectory(args.directory) \ No newline at end of file