diff --git a/insert_wordpress.py b/insert_wordpress.py index d59a35a..5faee26 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -69,15 +69,7 @@ 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 + author = articleacreator[0].text.lower() body = articlebody[0].find_all("p") bodyhtml = "
" for i in body: @@ -88,9 +80,14 @@ if __name__ == '__main__': bodyhtml = 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":author} + page = requests.get("http://localhost:8080/wp-json/wp/v2/users", auth=basic, params=params) + if page.status_code == 200: + result = page.json() + data["author"] = result[0]["id"] + params = {"search":title} page = requests.get("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, params=params)