-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathask_wit.py
executable file
·58 lines (44 loc) · 1.46 KB
/
ask_wit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Submit query to wit.ai for interpretation and present response.
Examples:
How many animals have tails?
Which animals eat berries?
Which animals do not eat berries?
How many animals do not eat berries?
Which animals eat mammals?
Does a bear have scales?
Does a bear have fur?
Do mammals live in the ocean?
What do coyotes eat?
Where does a salmon live?
"""
from __future__ import unicode_literals
import argparse
import logging
import sys
import urllib
import requests
# local
from animalia.config import Config
def parse_args():
parser = argparse.ArgumentParser(
description='Query wit animalia app',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('query', help='query to submit to wit animalia app')
parser.add_argument('-v', '--verbose', action='store_true', help='verbose output')
return parser.parse_args()
def query_wit(query):
url = 'https://api.wit.ai/message?v=20141022&q={0}'.format(
urllib.quote_plus(query))
headers = {'Accept': 'application/json',
'Authorization': 'Bearer {0}'.format(Config.wit_access_token)}
response = requests.get(url, headers=headers)
print('Response status: {0}'.format(response.status_code))
response_data = response.json()
print('Response data: {0}'.format(response_data))
if __name__ == "__main__":
args = parse_args()
query_wit(args.query)
sys.exit(0)