insert comment 75%
This commit is contained in:
parent
e3b9e92c23
commit
dc0fd0c781
@ -42,6 +42,19 @@ if __name__ == '__main__':
|
|||||||
articleacreator = soup.find_all("span", class_="articlecreator")
|
articleacreator = soup.find_all("span", class_="articlecreator")
|
||||||
dateheader = soup.find_all("div", class_="dateheader")
|
dateheader = soup.find_all("div", class_="dateheader")
|
||||||
itemfooter = soup.find_all("div", class_="itemfooter")
|
itemfooter = soup.find_all("div", class_="itemfooter")
|
||||||
|
comment = soup.find_all("div", class_="comment_item")
|
||||||
|
comment_post = []
|
||||||
|
for i in comment:
|
||||||
|
comment_item = i.text.split("\n")
|
||||||
|
footer = i.find_all("div", class_="itemfooter")
|
||||||
|
comment_author = footer[0].text.split(",")[0].replace("Posté par ", "")
|
||||||
|
comment_date = footer[0].find_all("abbr")[0].get("title")
|
||||||
|
comment_content = "<p>"
|
||||||
|
for j in range(0, len(comment_item)-2):
|
||||||
|
if len(comment_item[j]) > 0:
|
||||||
|
comment_content = comment_content + comment_item[j] + "<br />"
|
||||||
|
comment_content = comment_content + "</p>"
|
||||||
|
comment_post.append({"author": comment_author, "date": comment_date, "content": comment_content})
|
||||||
a = itemfooter[0].find_all("a", {"rel": True})
|
a = itemfooter[0].find_all("a", {"rel": True})
|
||||||
for i in a:
|
for i in a:
|
||||||
rel = i.get("rel")
|
rel = i.get("rel")
|
||||||
@ -80,7 +93,7 @@ if __name__ == '__main__':
|
|||||||
bodyhtml = bodyhtml + "</p>"
|
bodyhtml = bodyhtml + "</p>"
|
||||||
hour = articledate[0].text
|
hour = articledate[0].text
|
||||||
time = dateheader[0].text.split(" ")
|
time = dateheader[0].text.split(" ")
|
||||||
|
|
||||||
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"]}
|
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":author}
|
params = {"search":author}
|
||||||
page = requests.get("http://localhost:8080/wp-json/wp/v2/users", auth=basic, params=params)
|
page = requests.get("http://localhost:8080/wp-json/wp/v2/users", auth=basic, params=params)
|
||||||
@ -100,4 +113,12 @@ if __name__ == '__main__':
|
|||||||
if page_exist == False:
|
if page_exist == False:
|
||||||
page = requests.post("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, data=data)
|
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)
|
result = page.json()
|
||||||
|
print("Article ajoute : {0}".format(result["title"]["raw"]))
|
||||||
|
print(comment_post)
|
||||||
|
for i in comment_post:
|
||||||
|
data = {"post": result["id"], "content": i["content"], "date": i["date"]}
|
||||||
|
page = requests.post("http://localhost:8080/wp-json/wp/v2/comments", auth=basic, data=data)
|
||||||
|
print(page.status_code)
|
||||||
|
if page.status_code == 201:
|
||||||
|
print("Commentaire ajoute pour {0}".format(result["title"]["raw"]))
|
Loading…
x
Reference in New Issue
Block a user