diff --git a/insert_wordpress.py b/insert_wordpress.py index b2c2787..d59a35a 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -39,6 +39,7 @@ if __name__ == '__main__': articletitle = soup.find_all("h2", class_="articletitle") articlebody = soup.find_all("div", class_="articlebody") articledate = soup.find_all("span", class_="articledate") + articleacreator = soup.find_all("span", class_="articlecreator") dateheader = soup.find_all("div", class_="dateheader") itemfooter = soup.find_all("div", class_="itemfooter") a = itemfooter[0].find_all("a", {"rel": True}) @@ -68,6 +69,15 @@ if __name__ == '__main__': title = articletitle[0].text + author = articleacreator[0].text.lower() + author_exist = False + params = {"search":author} + page = requests.get("http://localhost:8080/wp-json/wp/v2/users", auth=basic, params=params) + if page.status_code == 200: + result = page.json() + print(result) + author_id = result[0]["id"] + author_exist = True body = articlebody[0].find_all("p") bodyhtml = "

" for i in body: @@ -76,10 +86,12 @@ if __name__ == '__main__': 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":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"]} + if author_exist == True: + data["author"] = author_id + params = {"search":title} page = requests.get("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, params=params) page_exist = True