def process_post(self, algorithm, useAt, data={}.copy()):
"""
handle POST to run the specified algorithm
:param algorithm: algorithm to run ("user/algorithm/version")
:param useAt: should '@' be prefixed to 'uid' (in POST body JSON)
:param data: additional params to send to the algorithm
:return:
"""
urlfetch.set_default_fetch_deadline(120)
uid = extract_uid(self.request.body)
if not uid:
return {'error':'Invalid Twitter Username'}
try:
data["query"] = '@'+uid if useAt else uid
cache_key = algorithm+' '+json.dumps(collections.OrderedDict(sorted(data.items())))
result = memcache.get(cache_key)
if result is None:
data["auth"] = TWITTER_AUTH_DICT
result = call_algorithmia(algorithm, data).result
memcache.add(cache_key, result, settings.AG_CACHE_SECONDS)
return result
except Exception as x:
return {'error': str(x)}
评论列表
文章目录