-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathknowledge.py
More file actions
35 lines (24 loc) · 984 Bytes
/
knowledge.py
File metadata and controls
35 lines (24 loc) · 984 Bytes
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
import requests
import auth
import wolframalpha
import translator
import pprint
service_url = 'https://kgsearch.googleapis.com/v1/entities:search'
def wiki_search(query, lang):
req = requests.get('https://kgsearch.googleapis.com/v1/entities:search',
params={'query': query,
'limit': 1,
'indent': True,
'key': auth.GOOGLE_KNOWLEDGE_KEY,
'languages': lang
})
response = req.json()
return response['itemListElement'][0]['result']['detailedDescription']['articleBody']
wolfram_client = wolframalpha.Client(auth.WOLFRAM_ALPHA_KEY)
def wolfram_search(query, lang):
global wolfram_client
query = translator.translate(lang, 'en', query)
print(query)
res = wolfram_client.query(query)
pprint.pprint(res)
return translator.translate('en', lang, next(res.results).text)