From 2279e4b0b6b4993821b1128a946b074e0cde442c Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 30 Aug 2023 22:39:59 +0200 Subject: [PATCH] search title album 50% --- import_export_canalblog.py | 2 +- lib/WPImport.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/import_export_canalblog.py b/import_export_canalblog.py index 78fdb0f..d5d2a18 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -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-album", dest=author, help="Define author for page album", default="") + import_parser.add_argument("--author-album", dest="author", help="Define author for page album", default="") diff --git a/lib/WPImport.py b/lib/WPImport.py index f1627ae..14d8c81 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -148,6 +148,7 @@ class WPimport: response = self._request.get(link) if response.status_code == 200: self._logger.info("{0} : get content info from web : {1}".format(self._name, link_o)) + page_img = response.content except ConnectionError as err: self._logger.error("{0} : Connection error for get album info : {1}".format(self._name, err)) exit(1) @@ -156,6 +157,13 @@ class WPimport: exit(1) else: self._logger.info("{0} : get album info from file : {1}".format(self._name, link_o)) + if os.path.exists("{0}/..{1}".format(self._directory, link_o)): + page_img = open("{0}/..{1}".format(self._directory, link_o), "r") + soup = BeautifulSoup(content, self._parser) + paragraph = soup.find("div", class_="albumbody").find("p") + author = paragraph.split("
")[1].split(":")[1].replace(" ", "").lower() + return author + def _addOrUpdateAlbum(self, soup): self._logger.info("{0} : Add/Update Album".format(self._name)) @@ -213,8 +221,14 @@ class WPimport: 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} + else: + link_a = albumbody.find_all("a") + href_a = link_a[0].get("href", "/") + author = self._getInfoAlbum(href_a) + self._logger.info("{0} : author : {1}".format(self._name, author)) + self._getAuthor(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): params = {"search": albumtitle, "per_page":100, "page": index}