diff --git a/insert_wordpress.py b/insert_wordpress.py index 780844d..a5a86eb 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -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 + "

" 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) + bodyhtml = bodyhtml.replace(i["old_href"], o.path) + bodyhtml = bodyhtml.replace(i["old_src"], o.path) hour = articledate[0].text time = dateheader[0].text.split(" ")