update image not fix
This commit is contained in:
parent
501876dac2
commit
404ad5dd6c
@ -80,20 +80,20 @@ class WPimport:
|
|||||||
r = requests.get("http://{0}/wp-json/wp/v2/media".format(self._wordpress), auth=self._basic, params=params)
|
r = requests.get("http://{0}/wp-json/wp/v2/media".format(self._wordpress), auth=self._basic, params=params)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
res = r.json()
|
res = r.json()
|
||||||
if len(res) == 0:
|
url = "http://{0}/wp-json/wp/v2/media".format(self._wordpress)
|
||||||
data = page.content
|
if len(res) > 0:
|
||||||
img_type = "image/png"
|
url = "http://{0}/wp-json/wp/v2/media/{1}".format(self._wordpress, res[0]["id"])
|
||||||
if img_name.split(".")[1] == "jpg" or img_name.split(".")[1] == "jpeg":
|
print(url)
|
||||||
img_type = "image/jpg"
|
data = page.content
|
||||||
headers={ 'Content-Type': img_type,'Content-Disposition' : 'attachment; filename={0}'.format(img_name)}
|
img_type = "image/png"
|
||||||
r = requests.post("http://{0}/wp-json/wp/v2/media".format(self._wordpress), auth=self._basic, headers=headers, data=data)
|
if img_name.split(".")[1] == "jpg" or img_name.split(".")[1] == "jpeg":
|
||||||
if r.status_code == 201:
|
img_type = "image/jpg"
|
||||||
res = r.json()
|
headers={ 'Content-Type': img_type,'Content-Disposition' : 'attachment; filename={0}'.format(img_name)}
|
||||||
media["id"] = res["id"]
|
r = requests.post(url, auth=self._basic, headers=headers, data=data)
|
||||||
media["rendered"] = res["guid"]["rendered"]
|
if r.status_code == 201 or r.status_code == 200:
|
||||||
else:
|
res = r.json()
|
||||||
media["id"] = res[0]["id"]
|
media["id"] = res["id"]
|
||||||
media["rendered"] = res[0]["guid"]["rendered"]
|
media["rendered"] = res["guid"]["rendered"]
|
||||||
return media
|
return media
|
||||||
|
|
||||||
## Add or Update post
|
## Add or Update post
|
||||||
|
Loading…
x
Reference in New Issue
Block a user