fix-featured-image #27
@ -170,6 +170,8 @@ 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-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-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("--no-image", help="No image add or update", dest="image", default="store_false", action="store_true")
|
||||||
|
import_parser.add_argument("--no-menu", help="No menu add or update", dest="menu", default="store_false", action="store_true")
|
||||||
|
|
||||||
import_parser.add_argument("--author", dest="author", help="Define author", default="")
|
import_parser.add_argument("--author", dest="author", help="Define author", default="")
|
||||||
|
|
||||||
|
|
||||||
@ -264,6 +266,7 @@ if __name__ == '__main__':
|
|||||||
for i in wordpress:
|
for i in wordpress:
|
||||||
importWp.setUrl(i)
|
importWp.setUrl(i)
|
||||||
importWp.fromFile(files=args.file.split(","))
|
importWp.fromFile(files=args.file.split(","))
|
||||||
|
if args.menu is False:
|
||||||
menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress)
|
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]))
|
menuWp.fromFile("{0}".format(args.file.split(",")[0]))
|
||||||
if len(args.directory) > 0:
|
if len(args.directory) > 0:
|
||||||
@ -276,6 +279,7 @@ if __name__ == '__main__':
|
|||||||
ex.submit(importDirectory, i, int(args.parallel), args.directory, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, args.create, args.update, args.image, args.revert, args.author)
|
ex.submit(importDirectory, i, int(args.parallel), args.directory, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, args.create, args.update, args.image, args.revert, args.author)
|
||||||
for i in range(0, int(args.parallel))
|
for i in range(0, int(args.parallel))
|
||||||
]
|
]
|
||||||
|
if args.menu is False:
|
||||||
wait(wait_for, return_when=ALL_COMPLETED)
|
wait(wait_for, return_when=ALL_COMPLETED)
|
||||||
menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress)
|
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}/index.html".format(args.directory))
|
menuWp.fromFile("{0}/index.html".format(args.directory))
|
||||||
@ -291,6 +295,7 @@ if __name__ == '__main__':
|
|||||||
ex.submit(importUrl, i, int(args.parallel), args.canalblog, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, ssl_canalblog, args.create, args.update, args.image, args.revert, args.tmp, args.author)
|
ex.submit(importUrl, i, int(args.parallel), args.canalblog, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, ssl_canalblog, args.create, args.update, args.image, args.revert, args.tmp, args.author)
|
||||||
for i in range(0, int(args.parallel))
|
for i in range(0, int(args.parallel))
|
||||||
]
|
]
|
||||||
|
if args.menu is False:
|
||||||
wait(wait_for, return_when=ALL_COMPLETED)
|
wait(wait_for, return_when=ALL_COMPLETED)
|
||||||
menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress)
|
menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress)
|
||||||
menuWp.fromUrl(args.canalblog)
|
menuWp.fromUrl(args.canalblog)
|
||||||
|
@ -417,22 +417,8 @@ class WPimport:
|
|||||||
subdirectory = self._getDirectories(sub, "{0}/{1}".format(item, i))
|
subdirectory = self._getDirectories(sub, "{0}/{1}".format(item, i))
|
||||||
return subdirectory
|
return subdirectory
|
||||||
|
|
||||||
## Add or update featured media
|
|
||||||
|
|
||||||
def _addOrUpdateFeaturedMedia(self, soup):
|
def _linkFeaturedMedia(self, img_src, h2, result):
|
||||||
item_div = soup.find_all("div", {"data-edittype": "post"})
|
|
||||||
for i in item_div:
|
|
||||||
h2 = i.find_all("h2")[0].text
|
|
||||||
params = {"search":h2, "type":"post"}
|
|
||||||
try:
|
|
||||||
page = self._request.get("{1}://{0}/wp-json/wp/v2/search".format(self._wordpress, self._protocol), auth=self._basic, params=params)
|
|
||||||
if page.status_code == 200:
|
|
||||||
result = page.json()
|
|
||||||
if len(result) > 0:
|
|
||||||
if h2 == result[0]["title"]:
|
|
||||||
img = i.find_all("img")
|
|
||||||
if len(img) > 0:
|
|
||||||
img_src = img[0].get("src")
|
|
||||||
try:
|
try:
|
||||||
page = self._request.get(img_src)
|
page = self._request.get(img_src)
|
||||||
if page.status_code == 200:
|
if page.status_code == 200:
|
||||||
@ -441,7 +427,6 @@ class WPimport:
|
|||||||
params = {"search": name_img}
|
params = {"search": name_img}
|
||||||
try:
|
try:
|
||||||
page = self._request.get("{1}://{0}/wp-json/wp/v2/media".format(self._wordpress, self._protocol), auth=self._basic, params=params)
|
page = self._request.get("{1}://{0}/wp-json/wp/v2/media".format(self._wordpress, self._protocol), auth=self._basic, params=params)
|
||||||
|
|
||||||
if page.status_code == 200:
|
if page.status_code == 200:
|
||||||
res = page.json()
|
res = page.json()
|
||||||
if len(res) > 0:
|
if len(res) > 0:
|
||||||
@ -467,7 +452,7 @@ class WPimport:
|
|||||||
self._logger.info("{0} : Get image for media featured : {1}".format(self._name, img_src.replace("_q", "")))
|
self._logger.info("{0} : Get image for media featured : {1}".format(self._name, img_src.replace("_q", "")))
|
||||||
media = self._addOrUpdateMedia(img_src.replace("_q", ""), page)
|
media = self._addOrUpdateMedia(img_src.replace("_q", ""), page)
|
||||||
if media["id"] != "":
|
if media["id"] != "":
|
||||||
self._addOrUpdateFeaturedMedia(soup)
|
self._linkFeaturedMedia(img_src.replace("_q", ""), h2)
|
||||||
else:
|
else:
|
||||||
self._logger.error("{0} : Connection error with status code for get image for featured media : {1}".format(self._name, page.status_code))
|
self._logger.error("{0} : Connection error with status code for get image for featured media : {1}".format(self._name, page.status_code))
|
||||||
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||||
@ -492,6 +477,24 @@ class WPimport:
|
|||||||
exit(1)
|
exit(1)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self._logger.error("{0} : Exception error for get featured media : {1}".format(self._name, err))
|
self._logger.error("{0} : Exception error for get featured media : {1}".format(self._name, err))
|
||||||
|
|
||||||
|
## Add or update featured media
|
||||||
|
|
||||||
|
def _addOrUpdateFeaturedMedia(self, soup):
|
||||||
|
item_div = soup.find_all("div", {"data-edittype": "post"})
|
||||||
|
for i in item_div:
|
||||||
|
h2 = i.find_all("h2")[0].text
|
||||||
|
params = {"search":h2, "type":"post"}
|
||||||
|
try:
|
||||||
|
page = self._request.get("{1}://{0}/wp-json/wp/v2/search".format(self._wordpress, self._protocol), auth=self._basic, params=params)
|
||||||
|
if page.status_code == 200:
|
||||||
|
result = page.json()
|
||||||
|
if len(result) > 0:
|
||||||
|
if h2 == self._replaceCaracter(result[0]["title"]):
|
||||||
|
img = i.find_all("img")
|
||||||
|
if len(img) > 0:
|
||||||
|
img_src = img[0].get("src")
|
||||||
|
self._linkFeaturedMedia(img_src, h2, result)
|
||||||
else:
|
else:
|
||||||
self._logger.error("{0} : Connection error with status code for featured media : {1}".format(self._name, page.status_code))
|
self._logger.error("{0} : Connection error with status code for featured media : {1}".format(self._name, page.status_code))
|
||||||
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user