Compare commits
4 Commits
9d41e57379
...
4.0.0
Author | SHA1 | Date | |
---|---|---|---|
b4d0fe8aa0 | |||
6401692d0d | |||
1fc9c48d2c | |||
d9c20cedcb |
@@ -170,7 +170,7 @@ if __name__ == '__main__':
|
||||
import_parser.add_argument("--no-create", help="No create post", dest="create", default="store_false", action="store_true")
|
||||
import_parser.add_argument("--no-update", help="No update post", dest="update", default="store_false", action="store_true")
|
||||
import_parser.add_argument("--no-image", help="No image add or update", dest="image", default="store_false", action="store_true")
|
||||
import_parser.add_argument("--author", help="Define author for page album", default="")
|
||||
import_parser.add_argument("--author-album", dest=author, help="Define author for page album", default="")
|
||||
|
||||
|
||||
|
||||
@@ -264,7 +264,6 @@ if __name__ == '__main__':
|
||||
for i in wordpress:
|
||||
importWp.setUrl(i)
|
||||
importWp.fromFile(files=args.file.split(","))
|
||||
exit(0)
|
||||
menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress)
|
||||
menuWp.fromFile("{0}".format(args.file.split(",")[0]))
|
||||
if len(args.directory) > 0:
|
||||
|
@@ -85,19 +85,28 @@ class WPMenu:
|
||||
def _getIdfromTitlePost(self, content):
|
||||
idMenu = {"id":0, "type":"", "link":""}
|
||||
soup = BeautifulSoup(content, self._parser)
|
||||
articletitle = soup.find("h2", class_="articletitle").get_text()
|
||||
articletitle = soup.find_all("h2", class_="articletitle")
|
||||
if len(articletitle) > 0:
|
||||
articletitle = articletitle[0].get_text()
|
||||
search = "posts"
|
||||
post_type = "post"
|
||||
if len(articletitle) == 0:
|
||||
articletitle = soup.find("div", class_="albumbody").find("h2").get_text()
|
||||
articletitle = soup.find_all("div", class_="albumbody")
|
||||
if len(articletitle) > 0:
|
||||
articletitle = articletitle[0].find("h2").get_text()
|
||||
search = "pages"
|
||||
post_type = "page"
|
||||
|
||||
exist = False
|
||||
for index in range(1,10):
|
||||
if exist is False:
|
||||
params = {"search":articletitle, "per_page":100, "page":index}
|
||||
try:
|
||||
self._logger.debug("{0} : Get Url for post : {1} {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/posts".format(self._wordpress, self._protocol_wordpress), params))
|
||||
page = self._request_wordpress.get("{1}://{0}/wp-json/wp/v2/posts".format(self._wordpress, self._protocol_wordpress), auth=self._basic, params=params)
|
||||
self._logger.debug("{0} : Get Url for {3} : {1} {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/{2}".format(self._wordpress, self._protocol_wordpress, search), params, search))
|
||||
page = self._request_wordpress.get("{1}://{0}/wp-json/wp/v2/{2}".format(self._wordpress, self._protocol_wordpress, search), auth=self._basic, params=params)
|
||||
if page.status_code == 200:
|
||||
result = page.json()
|
||||
self._logger.info("{0} : Get content post : {1}".format(self._name, len(result)))
|
||||
self._logger.info("{0} : Get content {2} : {1}".format(self._name, len(result), search))
|
||||
if len(result) > 0:
|
||||
for i in result:
|
||||
title_rendered = i["title"]["rendered"]
|
||||
@@ -105,8 +114,8 @@ class WPMenu:
|
||||
title_rendered = self._replaceCaracter(title_rendered)
|
||||
self._logger.debug("{0} : comparaison debug {1} {2}".format(self._name, articletitle, title_rendered))
|
||||
if articletitle == title_rendered:
|
||||
self._logger.debug("{0} : get post id : {1}".format(self._name, i))
|
||||
idMenu = {"id":i["id"], "type":"post", "link": i["link"]}
|
||||
self._logger.debug("{0} : get {2} id : {1}".format(self._name, i, search))
|
||||
idMenu = {"id":i["id"], "type":post_type, "link": i["link"]}
|
||||
exist = True
|
||||
else:
|
||||
self._logger.debug("{0} : {2} {1}".format(self._name, result, len(result)))
|
||||
@@ -156,13 +165,18 @@ class WPMenu:
|
||||
idMenu = {"id":0, "type":"", "link":""}
|
||||
if href != "#":
|
||||
title = href[::-1]
|
||||
second_title = title.split("/")[2]
|
||||
second_title = second_title[::-1]
|
||||
link = title.split("/")[0]
|
||||
link = link[::-1]
|
||||
title = title.split("/")[1]
|
||||
title = title[::-1]
|
||||
self._logger.info("{0} link {1} title {2}".format(self._name, link, title))
|
||||
if link == "index.html":
|
||||
idMenu = self._getId(title)
|
||||
if second_title == "albums":
|
||||
idMenu = self._getIdFromPost(href)
|
||||
else:
|
||||
idMenu = self._getId(title)
|
||||
else:
|
||||
idMenu = self._getIdFromPost(href)
|
||||
|
||||
|
Reference in New Issue
Block a user