premier essai d'insertion d'article reussi
This commit is contained in:
parent
0c41dc3e65
commit
491f15ae3c
@ -68,12 +68,27 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
|
|
||||||
title = articletitle[0].text
|
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
|
hour = articledate[0].text
|
||||||
time = dateheader[0].text.split(" ")
|
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)
|
if page_exist == False:
|
||||||
print(page.status_code)
|
page = requests.post("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, data=data)
|
||||||
if page.status_code == 201:
|
if page.status_code == 201:
|
||||||
print(page.content)
|
print(page.content)
|
Loading…
x
Reference in New Issue
Block a user