separate files method
This commit is contained in:
parent
193b0e6ef7
commit
55d62cebfb
@ -82,12 +82,31 @@ class WPimport:
|
||||
files = self._getFiles(directories)
|
||||
if args.revert is False:
|
||||
self._tmpFiles(files=files, number_thread=number_thread, max_thread=max_thread)
|
||||
self.fromFile()
|
||||
self._fromFileTmp()
|
||||
else:
|
||||
self._logger.error("{0} : No files for {1}".format(self._name, directory))
|
||||
|
||||
|
||||
def fromFile(self, files=[]):
|
||||
for i in range(0, len(files)):
|
||||
if os.path.exists(files[i]):
|
||||
self._logger.info("{0} : ({1}/{2}) File is being processed : {3}".format(self._name, i+1, currentRangeFiles + 1, files[i]))
|
||||
with open(files[i], 'r') as f:
|
||||
content = f.read()
|
||||
self._logger.debug("{0} : Size of article : {1}".format(self._name, len(content)))
|
||||
soup = BeautifulSoup(content, self._parser)
|
||||
articlebody = soup.find_all("div", class_="articlebody")
|
||||
self._logger.debug("{0} : Number of article : {1}".format(self._name, len(articlebody)))
|
||||
if len(articlebody) > 0:
|
||||
self._addOrUpdatePost(soup)
|
||||
else:
|
||||
self._addOrUpdateFeaturedMedia(soup)
|
||||
|
||||
|
||||
|
||||
# Private method
|
||||
|
||||
def _fromFileTmp(self):
|
||||
try:
|
||||
with open("{0}/{1}.json".format(self._tmp, self._name)) as file:
|
||||
files = json.loads(file.read())
|
||||
@ -107,9 +126,6 @@ class WPimport:
|
||||
self._addOrUpdateFeaturedMedia(soup)
|
||||
except Exception as ex:
|
||||
self._logger.error("{0} : Read file json from tmp : {1}".format(self._name, ex))
|
||||
|
||||
|
||||
# Private method
|
||||
|
||||
|
||||
def _tmpFiles(self, number_thread=1, max_thread=1):
|
||||
|
Loading…
x
Reference in New Issue
Block a user