add directory parameter
This commit is contained in:
parent
34115a3a7d
commit
9ab33c169e
@ -15,13 +15,15 @@ class WPimport:
|
|||||||
|
|
||||||
def fromDirectory(self, directory):
|
def fromDirectory(self, directory):
|
||||||
directory = "{0}/archives".format(directory)
|
directory = "{0}/archives".format(directory)
|
||||||
subdirectory = self._checkDirectory([], "{0}".format(directory))
|
directories = self._getDirectories([], "{0}".format(directory))
|
||||||
print(subdirectory)
|
files = self._getFiles(directories)
|
||||||
|
self.fromFile(files)
|
||||||
|
|
||||||
|
|
||||||
def fromFile(self, files):
|
def fromFile(self, files):
|
||||||
for file in files.split(","):
|
for file in files:
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
|
print(file)
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
soup = BeautifulSoup(content, 'html.parser')
|
soup = BeautifulSoup(content, 'html.parser')
|
||||||
@ -33,12 +35,24 @@ class WPimport:
|
|||||||
|
|
||||||
# Private method
|
# Private method
|
||||||
|
|
||||||
def _checkDirectory(self, subdirectory, item):
|
## Get all files
|
||||||
|
|
||||||
|
def _getFiles(self, item):
|
||||||
|
files = []
|
||||||
|
for i in item:
|
||||||
|
for j in os.listdir(i):
|
||||||
|
if os.path.isfile("{0}/{1}".format(i, j)):
|
||||||
|
files.append("{0}/{1}".format(i, j))
|
||||||
|
return files
|
||||||
|
|
||||||
|
## Get directories
|
||||||
|
|
||||||
|
def _getDirectories(self, subdirectory, item):
|
||||||
sub = subdirectory
|
sub = subdirectory
|
||||||
for i in os.listdir(item):
|
for i in os.listdir(item):
|
||||||
if os.path.isdir("{0}/{1}".format(item, i)):
|
if os.path.isdir("{0}/{1}".format(item, i)):
|
||||||
sub.append("{0}/{1}".format(item, i))
|
sub.append("{0}/{1}".format(item, i))
|
||||||
subdirectory = self._checkDirectory(sub, "{0}/{1}".format(item, i))
|
subdirectory = self._getDirectories(sub, "{0}/{1}".format(item, i))
|
||||||
return subdirectory
|
return subdirectory
|
||||||
|
|
||||||
## Add or update featured media
|
## Add or update featured media
|
||||||
@ -269,7 +283,7 @@ if __name__ == '__main__':
|
|||||||
basic = HTTPBasicAuth(args.user, password)
|
basic = HTTPBasicAuth(args.user, password)
|
||||||
importWp = WPimport(basic, args.wordpress)
|
importWp = WPimport(basic, args.wordpress)
|
||||||
if len(args.file) > 0:
|
if len(args.file) > 0:
|
||||||
importWp.fromFile(args.file)
|
importWp.fromFile(args.file.split(","))
|
||||||
exit(0)
|
exit(0)
|
||||||
if len(args.directory) > 0:
|
if len(args.directory) > 0:
|
||||||
importWp.fromDirectory(args.directory)
|
importWp.fromDirectory(args.directory)
|
Loading…
x
Reference in New Issue
Block a user