2017-01-17 1 views
1

모든 항목의 주가를 얻고 싶습니다. 나는 상품의 가격을 돌려주는 getPrice 기능을 가지고있다. wit ai을 사용하려고합니다. 이것은 내가 시도한 것입니다.파이썬에서 액션 함수 wit api를 호출하십시오.

from wit import Wit 

def getPrice(request): 
    #statements 
    return price 


def send(request, response): 
    print request['text'] 
    print('Sending to user...', response['text']) 

actions = { 
    'send': send, 
    'getPrice':getPrice 
} 

client = Wit(access_token="<token>", actions=actions) 

resp = client.message('what is the stock price of xyz') 
print('Result: ' + str(resp)) 

내가 무엇입니까 결과가이 :

Result: { 
u 'entities': { 
    u 'search_query': [{ 
     u 'suggested': True, 
     u 'confidence': 0.578445451443443, 
     u 'type': u 'value', 
     u 'value': u 'stock of xyz' 
    }], 
    u 'item': [{ 
     u 'confidence': 0.9613219630126943, 
     u 'value': u 'xyz' 
    }] 
}, 
u 'msg_id': u '5ac1a450-7c5d-3190-8666-5d88a1884f94', 
u '_text': u 'what is the stock of xyz?' 
} 

나는 봇 가격을 표시 할. 이 동작을 어떻게 호출 할 수 있습니까?

답변

0

당신은

print resp['entities']['item'][0]['value'] 
+0

그것은 형식 오류'주고 : 목록 지수는 – HunterrJ

+0

을 str'하지, 정수이어야합니다' xyz'는 결과가 아닙니다. 그것은 내가 얻으려고하는 주식입니다. – HunterrJ

+0

죄송합니다. 목록이 아니 었습니다. 업데이트했습니다. –

0

대신 수행 할 수 있습니다

print('Result: ' + str(resp)) 

을 시도 :

stock = resp['entities']['item'][0]['value'] 
print('Price: {}'.format(getPrice(stock))) 
관련 문제