add media in body html
This commit is contained in:
parent
c92f24e6af
commit
90881eb037
@ -49,6 +49,8 @@ class WPimport:
|
||||
href_img = img[0].get("src")
|
||||
page_img = requests.get(href_img)
|
||||
img_break = False
|
||||
new_img["old_src"]=href_img
|
||||
new_img["old_href"]=href_a
|
||||
if page_img.status_code == 404:
|
||||
href_img = href_a
|
||||
img_break = True
|
||||
@ -70,11 +72,13 @@ class WPimport:
|
||||
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()
|
||||
|
||||
new_img["old_src"]=href_img
|
||||
new_img["old_href"]=href_a
|
||||
new_img["id"]=res["id"]
|
||||
new_img["new_src"]=res["guid"]["rendered"]
|
||||
id_res = res["id"]
|
||||
rendered = res["guid"]["rendered"]
|
||||
else:
|
||||
id_res = res[0]["id"]
|
||||
rendered = res[0]["guid"]["rendered"]
|
||||
new_img["id"]=id_res
|
||||
new_img["new_src"]=rendered
|
||||
new_img["break"]=img_break
|
||||
list_img.append(new_img)
|
||||
|
||||
@ -126,14 +130,8 @@ class WPimport:
|
||||
bodyhtml = bodyhtml + "</p>"
|
||||
for i in list_img:
|
||||
o = urlparse(i["new_src"])
|
||||
if i == True:
|
||||
print(i["old_href"])
|
||||
bodyhtml = bodyhtml.replace(i["old_href"], o.path)
|
||||
else:
|
||||
print(i["old_src"])
|
||||
bodyhtml = bodyhtml.replace(i["old_src"], o.path)
|
||||
print(bodyhtml)
|
||||
exit(0)
|
||||
hour = articledate[0].text
|
||||
time = dateheader[0].text.split(" ")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user