premier essai d'insertion d'article reussi

This commit is contained in:
Valentin CZERYBA 2023-03-28 11:31:25 +02:00
parent 0c41dc3e65
commit 491f15ae3c

View File

@ -68,12 +68,27 @@ if __name__ == '__main__':
title = articletitle[0].text
body = articlebody[0]
body = articlebody[0].find_all("p")
bodyhtml = "<p>"
for i in body:
if len(i.text) == 1:
bodyhtml = bodyhtml + "<br />"
else:
bodyhtml = bodyhtml + str(i).replace("<p>", "").replace("</p>", "").replace("<br>", "<br />") + "<br />"
bodyhtml = bodyhtml + "</p>"
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
if 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)