From faa22f1438532d65e104cf9c471b924299f2264e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 1 Apr 2023 00:18:56 +0200 Subject: [PATCH] update post --- insert_wordpress.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/insert_wordpress.py b/insert_wordpress.py index 854c412..e327729 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -150,7 +150,14 @@ class WPimport: if len(result) == 0: page_exist = False else: - print("La page {0} existe deja".format(title)) + print("La page {0} existe deja et mis à jour".format(title)) + post_id = result[0]["id"] + page = requests.post("http://{0}/wp-json/wp/v2/posts/{1}".format(self.wordpress, post_id), auth=self.basic, data=data) + if page.status_code == 200: + result = page.json() + print("Article mis à jour : {0}".format(result["title"]["raw"])) + + if page_exist == False: page = requests.post("http://{0}/wp-json/wp/v2/posts".format(self.wordpress), auth=self.basic, data=data)