diff --git a/lib/WPChange.py b/lib/WPChange.py index 2cf58e5..b6e7b05 100644 --- a/lib/WPChange.py +++ b/lib/WPChange.py @@ -4,10 +4,11 @@ import requests, os, logging, re, json class WPRemove: # Constructor - def __init__(self, index_name=1, number_thread=1, logger=None): + def __init__(self, index_name=1, number_thread=1, logger=None, parser="html.parser"): self._name = "Thread-{0}".format(index_name) self._logger = logger self._number_thread = number_thread + self._parser = parser # Destructor def __del__(self): @@ -17,7 +18,7 @@ class WPRemove: # Public method ## from file - + def fromFile(self, files=[], number_thread=1, max_thread=1): divFiles = int(len(files) / max_thread) currentRangeFiles = int(divFiles * (number_thread+1)) @@ -30,17 +31,8 @@ class WPRemove: for i in range(firstRange, currentRangeFiles): 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) - + self._change(files[i]) + ## From directory @@ -76,3 +68,13 @@ class WPRemove: sub.append("{0}/{1}".format(item, i)) subdirectory = self._getDirectories(sub, "{0}/{1}".format(item, i)) return subdirectory + + ## Change path img file + + def _change(self, file): + with open(file, 'r') as f: + content = f.read() + soup = BeautifulSoup(content, self._parser) + img = soup.find_all("img") + +