wip directory

This commit is contained in:
Valentin CZERYBA 2023-04-06 21:53:56 +02:00
parent 5768b37cd1
commit 1f7e442d04

View File

@ -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)
if len(args.file) > 0:
importWp.fromFile(args.file)
exit(0)
if len(args.directory) > 0:
importWp.fromDirectory(args.directory)