From ba511bc6c4251b7987712481a4ad98a2737d31e4 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 4 Apr 2023 22:14:10 +0200 Subject: [PATCH] Ajout print image ajoute --- insert_wordpress.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/insert_wordpress.py b/insert_wordpress.py index fd878cd..1f6812c 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -13,23 +13,21 @@ class WPimport: # Public method - def fromFile(self, file): - with open(file, 'r') as f: - content = f.read() - soup = BeautifulSoup(content, 'html.parser') - articlebody = soup.find_all("div", class_="articlebody") - if len(articlebody) > 0: - self._addOrUpdatePost(soup) - else: - self._addOrUpdateFeaturedMedia(soup) + def fromFile(self, files): + for file in files.split(","): + with open(file, 'r') as f: + content = f.read() + soup = BeautifulSoup(content, 'html.parser') + articlebody = soup.find_all("div", class_="articlebody") + if len(articlebody) > 0: + self._addOrUpdatePost(soup) + else: + self._addOrUpdateFeaturedMedia(soup) # Private method ## Add or update featured media - - ## Get or update featured image - def _addOrUpdateFeaturedMedia(self, soup): item_div = soup.find_all("div", {"data-edittype": "post"}) for i in item_div: @@ -92,6 +90,7 @@ class WPimport: headers={ 'Content-Type': img_type,'Content-Disposition' : 'attachment; filename={0}'.format(img_name)} r = requests.post("http://{0}/wp-json/wp/v2/media".format(self._wordpress), auth=self._basic, headers=headers, data=data) if r.status_code == 201: + print("Ajout d'image {0}".format(img_name)) res = r.json() media["id"] = res["id"] media["rendered"] = res["guid"]["rendered"]