add private method for association id

This commit is contained in:
Valentin CZERYBA 2023-04-02 13:06:10 +02:00
parent 4054f41e9b
commit f07f8c040f

View File

@ -16,6 +16,13 @@ class WPimport:
contents = f.read()
self.insertWordpress(contents)
def _linkImgPost(self, title, list_img, post_id):
for i in list_img:
data = {"post": post_id}
r = requests.post("http://{0}/wp-json/wp/v2/media/{1}".format(self.wordpress, i["id"]), auth=self.basic, data=data)
if r.status_code == 200:
print("Association d'une image à l'article {0}".format(title))
def insertWordpress(self, content):
tags = []
month = {"janvier":"01", "février": "02", "mars": "03", "avril":"04", "mai": "05", "juin": "06", "juillet": "07", "août": "08", "septembre": "09", "octobre": "10", "novembre": "11", "décembre": "12"}
@ -156,6 +163,7 @@ class WPimport:
if page.status_code == 200:
result = page.json()
print("Article mis à jour : {0}".format(result["title"]["raw"]))
self._linkImgPost(result["title"]["raw"], list_img, result["id"])
@ -169,12 +177,7 @@ class WPimport:
page = requests.post("http://{0}/wp-json/wp/v2/comments".format(self.wordpress), auth=self.basic, data=data)
if page.status_code == 201:
print("Commentaire ajoute pour {0}".format(result["title"]["raw"]))
for i in list_img:
data = {"post": result["id"]}
r = requests.post("http://{0}/wp-json/wp/v2/media/{1}".format(self.wordpress, i["id"]), auth=self.basic, data=data)
if r.status_code == 200:
print("Association d'une image à l'article {0}".format(result["title"]["raw"]))
self._linkImgPost(result["title"]["raw"], list_img, result["id"])