WPchange wip
This commit is contained in:
parent
3e76892676
commit
c631909cb6
@ -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):
|
||||
@ -30,16 +31,7 @@ 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")
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user