From 72a86536caac77f7044b94411a4ae75c9536d861 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 24 Feb 2015 15:34:11 -0500 Subject: [PATCH 1/2] Added facetagging --- alchemyapi.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/alchemyapi.py b/alchemyapi.py index 2f64b5a..860d6fd 100644 --- a/alchemyapi.py +++ b/alchemyapi.py @@ -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' @@ -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. @@ -757,3 +778,4 @@ def __analyze(self, endpoint, params, post_data=bytearray()): print(results) print(e) return {'status': 'ERROR', 'statusInfo': 'parse-error'} + From 026c98236f8db16415647168cd8f7719449b4da8 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 24 Feb 2015 15:35:43 -0500 Subject: [PATCH 2/2] removed whitespace --- alchemyapi.py | 1 - 1 file changed, 1 deletion(-) diff --git a/alchemyapi.py b/alchemyapi.py index 860d6fd..34ded5b 100644 --- a/alchemyapi.py +++ b/alchemyapi.py @@ -778,4 +778,3 @@ def __analyze(self, endpoint, params, post_data=bytearray()): print(results) print(e) return {'status': 'ERROR', 'statusInfo': 'parse-error'} -