diff --git a/insert_wordpress.py b/insert_wordpress.py
index 86fab01..595a3d6 100644
--- a/insert_wordpress.py
+++ b/insert_wordpress.py
@@ -68,12 +68,27 @@ if __name__ == '__main__':
title = articletitle[0].text
- body = articlebody[0]
+ body = articlebody[0].find_all("p")
+ bodyhtml = "
"
+ for i in body:
+ if len(i.text) == 1:
+ bodyhtml = bodyhtml + "
"
+ else:
+ bodyhtml = bodyhtml + str(i).replace("
", "").replace("
", "").replace("
", "
") + "
"
+ bodyhtml = bodyhtml + ""
+ print(bodyhtml)
hour = articledate[0].text
time = dateheader[0].text.split(" ")
- data = {"title":title, "content":body, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": listelement["tags"], "categories": listelement["categories"]}
+ data = {"title":title, "content":bodyhtml, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": listelement["tags"], "categories": listelement["categories"]}
+ params = {"search":title}
+ page = requests.get("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, params=params)
+ page_exist = True
+ if page.status_code:
+ result= page.json()
+ if len(result) == 0:
+ page_exist = False
- page = requests.post("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, data=data)
- print(page.status_code)
- if page.status_code == 201:
- print(page.content)
\ No newline at end of file
+ if page_exist == False:
+ page = requests.post("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, data=data)
+ if page.status_code == 201:
+ print(page.content)
\ No newline at end of file