delete and replace image
This commit is contained in:
parent
404ad5dd6c
commit
665f1474f2
@ -59,7 +59,7 @@ class WPimport:
|
||||
if r.status_code == 200:
|
||||
print("Ajout media featured : {0}".format(r.json()["title"]["raw"]))
|
||||
else:
|
||||
print("Aucun media trouvé")
|
||||
print("Aucun media trouvé pour {0}".format(h2))
|
||||
|
||||
## Association image to post
|
||||
|
||||
@ -80,17 +80,18 @@ class WPimport:
|
||||
r = requests.get("http://{0}/wp-json/wp/v2/media".format(self._wordpress), auth=self._basic, params=params)
|
||||
if r.status_code == 200:
|
||||
res = r.json()
|
||||
url = "http://{0}/wp-json/wp/v2/media".format(self._wordpress)
|
||||
if len(res) > 0:
|
||||
url = "http://{0}/wp-json/wp/v2/media/{1}".format(self._wordpress, res[0]["id"])
|
||||
print(url)
|
||||
params = {"force":1}
|
||||
r = requests.delete("http://{0}/wp-json/wp/v2/media/{1}".format(self._wordpress, res[0]["id"]), auth=self._basic, params=params)
|
||||
if r.status_code == 200:
|
||||
print("Image supprimé {0}".format(img_name))
|
||||
data = page.content
|
||||
img_type = "image/png"
|
||||
if img_name.split(".")[1] == "jpg" or img_name.split(".")[1] == "jpeg":
|
||||
img_type = "image/jpg"
|
||||
headers={ 'Content-Type': img_type,'Content-Disposition' : 'attachment; filename={0}'.format(img_name)}
|
||||
r = requests.post(url, auth=self._basic, headers=headers, data=data)
|
||||
if r.status_code == 201 or r.status_code == 200:
|
||||
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:
|
||||
res = r.json()
|
||||
media["id"] = res["id"]
|
||||
media["rendered"] = res["guid"]["rendered"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user