I’m using Python (requests) and WP API to transfer some posts from WordPress blog to my main portal. My problem is that I can’t find a good way to retrieve the “featured_image” from wordpress blog.
My python function gets a list of all posts from an specific tag:
def get_posts(self):
r = requests.get('http://papodebuteco.blog.br/wp-json/wp/v2/posts?tag=uberlandiahome?_embed',)
# we have the result on http://papodebuteco.blog.br/wp-json/wp/v2/posts?tag=uberlandiahome?_embed
if r.ok:
data = json.loads(r.content.encode('UTF-8'))
for post in data:
image_id = post['featured_image'] #it gives me a 275 id to be used on the next line
req = requests.get('http://papodebuteco.blog.br/wp-json/wp/v2/media/%d'% image_id)
# eg. http://papodebuteco.blog.br/wp-json/wp/v2/media/275/
content = json.loads(req.content.encode('UTF-8'))
print content['guid']
else:pass
On the final result everything I need will be retrieve the posts from WordPress Blog and save it (inc. featured image) on Django database. Is there any good way to do that?