Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions alchemyapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class AlchemyAPI:
ENDPOINTS['imagetagging'] = {}
ENDPOINTS['imagetagging']['url'] = '/url/URLGetRankedImageKeywords'
ENDPOINTS['imagetagging']['image'] = '/image/ImageGetRankedImageKeywords'
ENDPOINTS['facetagging'] = {}
ENDPOINTS['facetagging']['url'] = '/url/URLGetRankedImageFaceTags'
ENDPOINTS['facetagging']['image'] = '/image/ImageGetRankedImageFaceTags'
ENDPOINTS['taxonomy'] = {}
ENDPOINTS['taxonomy']['url'] = '/url/URLGetRankedTaxonomy'
ENDPOINTS['taxonomy']['html'] = '/html/HTMLGetRankedTaxonomy'
Expand Down Expand Up @@ -720,6 +723,24 @@ def imageTagging(self, flavor, data, options={}):
options[flavor] = data
return self.__analyze(AlchemyAPI.ENDPOINTS['imagetagging'][flavor], {}, options)

def faceTagging(self, flavor, data, options={}):
"""

INPUT:
flavor -> which version of the call only url or image.
data -> the data to analyze, either the the url or path to image.
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
"""
if flavor not in AlchemyAPI.ENDPOINTS['facetagging']:
return {'status': 'ERROR', 'statusInfo': 'facetagging for ' + flavor + ' not available'}
elif 'image' == flavor:
image = open(data, 'rb').read()
options['imagePostMode'] = 'raw'
return self.__analyze(AlchemyAPI.ENDPOINTS['facetagging'][flavor], options, image)

options[flavor] = data
return self.__analyze(AlchemyAPI.ENDPOINTS['facetagging'][flavor], {}, options)

def __analyze(self, endpoint, params, post_data=bytearray()):
"""
HTTP Request wrapper that is called by the endpoint functions. This function is not intended to be called through an external interface.
Expand Down