remove private method for featured media
This commit is contained in:
parent
f77274f00e
commit
c9b1264153
@ -20,36 +20,8 @@ class WPimport:
|
|||||||
articlebody = soup.find_all("div", class_="articlebody")
|
articlebody = soup.find_all("div", class_="articlebody")
|
||||||
if len(articlebody) > 0:
|
if len(articlebody) > 0:
|
||||||
self._addOrUpdatePost(soup)
|
self._addOrUpdatePost(soup)
|
||||||
else:
|
|
||||||
self._addOrUpdateFeaturedMedia(soup)
|
|
||||||
|
|
||||||
# Private method
|
# Private method
|
||||||
|
|
||||||
|
|
||||||
## Get or update featured image
|
|
||||||
|
|
||||||
def _addOrUpdateFeaturedMedia(self, soup):
|
|
||||||
item_div = soup.find_all("div", {"data-edittype": "post"})
|
|
||||||
for i in item_div:
|
|
||||||
h2 = i.find_all("h2")[0].text
|
|
||||||
params = {"search":h2, "type":"post"}
|
|
||||||
page = requests.get("http://{0}/wp-json/wp/v2/search".format(self._wordpress), auth=self._basic, params=params)
|
|
||||||
if page.status_code == 200:
|
|
||||||
result = page.json()
|
|
||||||
if len(result) > 0:
|
|
||||||
if h2 == result[0]["title"]:
|
|
||||||
img = i.find_all("img")
|
|
||||||
if len(img) > 0:
|
|
||||||
img_src = img[0].get("src")
|
|
||||||
page = requests.get(img_src)
|
|
||||||
if page.status_code == 200:
|
|
||||||
media=self._addOrUpdateMedia(img_src, page)
|
|
||||||
headers = {'Content-Type': 'application/json', 'Accept':'application/json'}
|
|
||||||
data = {"featured_media": media["id"]}
|
|
||||||
r = requests.post("http://{0}/wp-json/wp/v2/posts/{1}".format(self._wordpress, result[0]["id"]), auth=self._basic, headers=headers, data=json.dumps(data))
|
|
||||||
if r.status_code == 200:
|
|
||||||
print("Ajout media featured : {0}".format(r.json()["title"]["raw"]))
|
|
||||||
|
|
||||||
|
|
||||||
## Association image to post
|
## Association image to post
|
||||||
|
|
||||||
@ -184,7 +156,7 @@ class WPimport:
|
|||||||
bodyhtml = bodyhtml.replace(i["old_src"], o.path)
|
bodyhtml = bodyhtml.replace(i["old_src"], o.path)
|
||||||
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"], "featured_media":list_img[0]["id"]}
|
||||||
params = {"search":author}
|
params = {"search":author}
|
||||||
page = requests.get("http://{0}/wp-json/wp/v2/users".format(self._wordpress), auth=self._basic, params=params)
|
page = requests.get("http://{0}/wp-json/wp/v2/users".format(self._wordpress), auth=self._basic, params=params)
|
||||||
if page.status_code == 200:
|
if page.status_code == 200:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user