insert #6

Merged
v4l3n71n merged 60 commits from insert into master 2023-04-11 21:29:54 +00:00
Showing only changes of commit 491f15ae3c - Show all commits

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)