add method getAuthor
This commit is contained in:
parent
d88ae7ed44
commit
9d41e57379
@ -259,13 +259,13 @@ if __name__ == '__main__':
|
|||||||
basic = HTTPBasicAuth(args.user, password)
|
basic = HTTPBasicAuth(args.user, password)
|
||||||
if args.command == "import":
|
if args.command == "import":
|
||||||
wordpress = args.wordpress.split(",")
|
wordpress = args.wordpress.split(",")
|
||||||
importWp = WPimport(basic=basic, wordpress="", logger=logger, parser=args.parser, ssl_wordpress=ssl_wordpress)
|
importWp = WPimport(basic=basic, wordpress="", logger=logger, parser=args.parser, ssl_wordpress=ssl_wordpress, author=args.author)
|
||||||
if len(args.file) > 0:
|
if len(args.file) > 0:
|
||||||
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(","))
|
||||||
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, author=args.author)
|
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:
|
||||||
try:
|
try:
|
||||||
|
@ -115,6 +115,30 @@ class WPimport:
|
|||||||
|
|
||||||
# Private method
|
# Private method
|
||||||
|
|
||||||
|
|
||||||
|
def _getAuthor(self, author):
|
||||||
|
params = {"search":author, "per_page":100}
|
||||||
|
author = 0
|
||||||
|
try:
|
||||||
|
self._logger.info("{0} : Search author : {1}".format(self._name, author))
|
||||||
|
page = self._request.get("{1}://{0}/wp-json/wp/v2/users".format(self._wordpress, self._protocol), auth=self._basic, headers=self._headers_json, params=params)
|
||||||
|
self._logger.debug("{0} : End Search author : {1}".format(self._name, author))
|
||||||
|
self._logger.debug("{0} : Debug requests : {1}".format(self._name, page.content))
|
||||||
|
if page.status_code == 200:
|
||||||
|
self._logger.info("{0} : Get author : {1}".format(self._name, author))
|
||||||
|
result = page.json()
|
||||||
|
for a in result:
|
||||||
|
author = a["id"]
|
||||||
|
else:
|
||||||
|
self._logger.error("{0} : Connection error with status code for get author : {1}".format(self._name, page.status_code))
|
||||||
|
self._logger.debug("{0} : {1}".format(page.content))
|
||||||
|
except ConnectionError as err:
|
||||||
|
self._logger.error("{0} : Connection error for get author : {1}".format(self._name, err))
|
||||||
|
exit(1)
|
||||||
|
except Exception as err:
|
||||||
|
self._logger.error("{0} : Exception error for get author : {1}".format(self._name, err))
|
||||||
|
return author
|
||||||
|
|
||||||
def _addOrUpdateAlbum(self, soup):
|
def _addOrUpdateAlbum(self, soup):
|
||||||
self._logger.info("{0} : Add/Update Album".format(self._name))
|
self._logger.info("{0} : Add/Update Album".format(self._name))
|
||||||
albumbody = soup.find("div", class_="albumbody")
|
albumbody = soup.find("div", class_="albumbody")
|
||||||
@ -169,7 +193,11 @@ class WPimport:
|
|||||||
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:
|
||||||
data = {"title":albumtitle, "content":content_html, "status":"publish"}
|
data = {"title":albumtitle, "content":content_html, "status":"publish"}
|
||||||
|
if len(self._author) > 0:
|
||||||
|
author = self._getAuthor(self._author)
|
||||||
|
if author != 0:
|
||||||
|
data = {"title":albumtitle, "content":content_html, "status":"publish", "author":author}
|
||||||
|
self._logger.debug("{0} : data for album page : {1}".format(self._name, data))
|
||||||
for index in range(1,10):
|
for index in range(1,10):
|
||||||
params = {"search": albumtitle, "per_page":100, "page": index}
|
params = {"search": albumtitle, "per_page":100, "page": index}
|
||||||
try:
|
try:
|
||||||
@ -800,25 +828,7 @@ class WPimport:
|
|||||||
data = {"title":title, "content":bodyhtml, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": listelement["tags"], "categories": listelement["categories"]}
|
data = {"title":title, "content":bodyhtml, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": listelement["tags"], "categories": listelement["categories"]}
|
||||||
self._logger.debug("{0} : Data for post : |{1}| : {2}" .format(self._name, title, data))
|
self._logger.debug("{0} : Data for post : |{1}| : {2}" .format(self._name, title, data))
|
||||||
|
|
||||||
params = {"search":author, "per_page":100}
|
data["author"] = self._getAuthor(author)
|
||||||
try:
|
|
||||||
self._logger.info("{0} : Search author : {1}".format(self._name, author))
|
|
||||||
page = self._request.get("{1}://{0}/wp-json/wp/v2/users".format(self._wordpress, self._protocol), auth=self._basic, headers=self._headers_json, params=params)
|
|
||||||
self._logger.debug("{0} : End Search author : {1}".format(self._name, author))
|
|
||||||
self._logger.debug("{0} : Debug requests : {1}".format(self._name, page.content))
|
|
||||||
if page.status_code == 200:
|
|
||||||
self._logger.info("{0} : Get author id : {1}".format(self._name, result))
|
|
||||||
result = page.json()
|
|
||||||
for a in result:
|
|
||||||
data["author"] = a["id"]
|
|
||||||
else:
|
|
||||||
self._logger.error("{0} : Connection error with status code for get author : {1}".format(self._name, page.status_code))
|
|
||||||
self._logger.debug("{0} : {1}".format(page.content))
|
|
||||||
except ConnectionError as err:
|
|
||||||
self._logger.error("{0} : Connection error for get author : {1}".format(self._name, err))
|
|
||||||
exit(1)
|
|
||||||
except Exception as err:
|
|
||||||
self._logger.error("{0} : Exception error for get author : {1}".format(self._name, err))
|
|
||||||
page_is_exist = False
|
page_is_exist = False
|
||||||
|
|
||||||
for index in range(1,10):
|
for index in range(1,10):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user