add author
This commit is contained in:
parent
50bf31d334
commit
d88ae7ed44
@ -67,7 +67,7 @@ def download(name_thread, max_thread, url, logger, parser, directory, html, img,
|
|||||||
del exportWp
|
del exportWp
|
||||||
|
|
||||||
|
|
||||||
def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, basic, serial, ssl_wordpress, ssl_canalblog, create, update, image, revert, tmp):
|
def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, basic, serial, ssl_wordpress, ssl_canalblog, create, update, image, revert, tmp, author):
|
||||||
canalblog = canalblog.split(",")
|
canalblog = canalblog.split(",")
|
||||||
wordpress = wordpress.split(",")
|
wordpress = wordpress.split(",")
|
||||||
name = "Thread-{0}".format(int(name_thread) + 1)
|
name = "Thread-{0}".format(int(name_thread) + 1)
|
||||||
@ -88,7 +88,7 @@ def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, bas
|
|||||||
exportWp.getUrlPage(name_thread, max_thread)
|
exportWp.getUrlPage(name_thread, max_thread)
|
||||||
del exportWp
|
del exportWp
|
||||||
for j in wordpress:
|
for j in wordpress:
|
||||||
importWp = WPimport(name=name, basic=basic, wordpress=j, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp)
|
importWp = WPimport(name=name, basic=basic, wordpress=j, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp, author=author)
|
||||||
for k in ["article", "page"]:
|
for k in ["article", "page"]:
|
||||||
for l in ["publications", "principal"]:
|
for l in ["publications", "principal"]:
|
||||||
importWp.fromUrl(l, k)
|
importWp.fromUrl(l, k)
|
||||||
@ -110,7 +110,7 @@ def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, bas
|
|||||||
if not revert:
|
if not revert:
|
||||||
exportWp.getUrlPage(name_thread, max_thread)
|
exportWp.getUrlPage(name_thread, max_thread)
|
||||||
del exportWp
|
del exportWp
|
||||||
importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp)
|
importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp, author=author)
|
||||||
|
|
||||||
for k in ["article", "page"]:
|
for k in ["article", "page"]:
|
||||||
for l in ["publications", "principal"]:
|
for l in ["publications", "principal"]:
|
||||||
@ -119,13 +119,13 @@ def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, bas
|
|||||||
del importWp
|
del importWp
|
||||||
|
|
||||||
|
|
||||||
def importDirectory(name_thread, max_thread, directory, logger, parser, wordpress, basic, serial, ssl_wordpress, create, update, image, revert):
|
def importDirectory(name_thread, max_thread, directory, logger, parser, wordpress, basic, serial, ssl_wordpress, create, update, image, revert, author):
|
||||||
name = "Thread-{0}".format(int(name_thread) + 1)
|
name = "Thread-{0}".format(int(name_thread) + 1)
|
||||||
directory = directory.split(",")
|
directory = directory.split(",")
|
||||||
wordpress = wordpress.split(",")
|
wordpress = wordpress.split(",")
|
||||||
if serial is False:
|
if serial is False:
|
||||||
for i in wordpress:
|
for i in wordpress:
|
||||||
importWp = WPimport(name=name, basic=basic, wordpress=i, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image)
|
importWp = WPimport(name=name, basic=basic, wordpress=i, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, author=author)
|
||||||
for j in directory:
|
for j in directory:
|
||||||
importWp.fromDirectory(j, name_thread, max_thread, revert)
|
importWp.fromDirectory(j, name_thread, max_thread, revert)
|
||||||
del importWp
|
del importWp
|
||||||
@ -135,7 +135,7 @@ def importDirectory(name_thread, max_thread, directory, logger, parser, wordpres
|
|||||||
logger.error("{0} : Error : Number directory is different than wordpress".format(name))
|
logger.error("{0} : Error : Number directory is different than wordpress".format(name))
|
||||||
exit(1)
|
exit(1)
|
||||||
for i in range(0, len(wordpress)-1):
|
for i in range(0, len(wordpress)-1):
|
||||||
importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image)
|
importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, author=author)
|
||||||
importWp.fromDirectory(directory[i], name_thread, max_thread, revert)
|
importWp.fromDirectory(directory[i], name_thread, max_thread, revert)
|
||||||
del importWp
|
del importWp
|
||||||
|
|
||||||
@ -170,6 +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-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("--author", help="Define author for page album", default="")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -264,7 +265,7 @@ if __name__ == '__main__':
|
|||||||
importWp.setUrl(i)
|
importWp.setUrl(i)
|
||||||
importWp.fromFile(files=args.file.split(","))
|
importWp.fromFile(files=args.file.split(","))
|
||||||
exit(0)
|
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 = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress, author=args.author)
|
||||||
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:
|
||||||
try:
|
try:
|
||||||
@ -273,7 +274,7 @@ if __name__ == '__main__':
|
|||||||
wait(wait_for, return_when=ALL_COMPLETED)
|
wait(wait_for, return_when=ALL_COMPLETED)
|
||||||
errorRevert(logger, args.revert, args.tmp)
|
errorRevert(logger, args.revert, args.tmp)
|
||||||
wait_for = [
|
wait_for = [
|
||||||
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)
|
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))
|
||||||
]
|
]
|
||||||
wait(wait_for, return_when=ALL_COMPLETED)
|
wait(wait_for, return_when=ALL_COMPLETED)
|
||||||
@ -288,7 +289,7 @@ if __name__ == '__main__':
|
|||||||
wait(wait_for, return_when=ALL_COMPLETED)
|
wait(wait_for, return_when=ALL_COMPLETED)
|
||||||
errorRevert(logger, args.revert, args.tmp)
|
errorRevert(logger, args.revert, args.tmp)
|
||||||
wait_for = [
|
wait_for = [
|
||||||
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)
|
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))
|
||||||
]
|
]
|
||||||
wait(wait_for, return_when=ALL_COMPLETED)
|
wait(wait_for, return_when=ALL_COMPLETED)
|
||||||
|
@ -8,7 +8,7 @@ from requests.packages.urllib3.util.retry import Retry
|
|||||||
|
|
||||||
class WPimport:
|
class WPimport:
|
||||||
# Constructor
|
# Constructor
|
||||||
def __init__(self, name="Thread-0", basic=None, wordpress="", logger=None, parser="html.parser", ssl_wordpress=True, no_create=False, no_update=False, no_image=False, tmp="/tmp/import_export_canablog"):
|
def __init__(self, name="Thread-0", basic=None, wordpress="", logger=None, parser="html.parser", ssl_wordpress=True, no_create=False, no_update=False, no_image=False, tmp="/tmp/import_export_canablog", author=""):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._basic = basic
|
self._basic = basic
|
||||||
self._wordpress = wordpress
|
self._wordpress = wordpress
|
||||||
@ -29,6 +29,7 @@ class WPimport:
|
|||||||
self._no_update = no_update
|
self._no_update = no_update
|
||||||
self._no_image = no_image
|
self._no_image = no_image
|
||||||
self._tmp = tmp
|
self._tmp = tmp
|
||||||
|
self._author = author
|
||||||
|
|
||||||
# Destructor
|
# Destructor
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
@ -131,10 +132,10 @@ class WPimport:
|
|||||||
new_img = {}
|
new_img = {}
|
||||||
href_img = i.get("src")
|
href_img = i.get("src")
|
||||||
href_img_o = urlparse(href_img)
|
href_img_o = urlparse(href_img)
|
||||||
new_img["old_src"]=href_img
|
|
||||||
try:
|
try:
|
||||||
if len(href_img_o.netloc) > 0:
|
if len(href_img_o.netloc) > 0:
|
||||||
img_ok = False
|
img_ok = False
|
||||||
|
href_img = href_img.replace("_q", "_o")
|
||||||
page_img = self._request.get(href_img)
|
page_img = self._request.get(href_img)
|
||||||
if page_img.status_code == 200:
|
if page_img.status_code == 200:
|
||||||
img_ok = True
|
img_ok = True
|
||||||
@ -158,14 +159,12 @@ class WPimport:
|
|||||||
content_html = ""
|
content_html = ""
|
||||||
if len(list_img) > 0:
|
if len(list_img) > 0:
|
||||||
|
|
||||||
content_html = "<!-- wp:paragraph --><p>{0}</p><!-- /wp:paragraph -->\n\n".format(albumdesc)
|
content_html = "<!-- wp:paragraph -->\n{0}\n<!-- /wp:paragraph -->\n\n".format(albumdesc)
|
||||||
|
|
||||||
|
|
||||||
content_html = content_html + "<figure class='wp-block-gallery has-nested-images columns-default is-cropped'><!-- wp:image {\"id\":id-image,'sizeSlug':'large','linkDestination':'none'} --><figure class='wp-block-image size-large'><img src='src-image' alt='' class=wp-image-id-image/></figure><!-- /wp:image --> \n\n".replace("id-image", str(list_img[0]["id"])).replace("src-image", list_img[0]["new_src"])
|
|
||||||
|
|
||||||
for i in range(1, len(list_img)):
|
for i in range(0, len(list_img)):
|
||||||
content_html = content_html + "<!-- wp:image {\"id\":id-image,\"sizeSlug\":\"large\",\"linkDestination\":\"none\"} --><figure class=\"wp-block-image size-large\"><img src='src-image' alt=\"\" class='wp-image-id-image'/></figure><!-- /wp:image -->\n\n".replace("id-image", str(list_img[0]["id"])).replace("src-image", list_img[0]["new_src"])
|
content_html = content_html + "<!-- wp:image {\"id\":id-image,\"sizeSlug\":\"large\",\"linkDestination\":\"none\"} --><figure class=\"wp-block-image size-large\"><img src=\"src-image\" alt=\"\" class=\"wp-image-id-image\"/></figure><!-- /wp:image -->\n\n".replace("id-image", str(list_img[i]["id"])).replace("src-image", list_img[i]["new_src"])
|
||||||
content_html = content_html + "<!-- /wp:gallery -->"
|
|
||||||
|
|
||||||
self._logger.info("{0} : content html : {1}".format(self._name, content_html))
|
self._logger.info("{0} : content html : {1}".format(self._name, content_html))
|
||||||
if len(content_html) > 0:
|
if len(content_html) > 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user