-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleKnowledgeGraph.py
More file actions
34 lines (27 loc) · 840 Bytes
/
GoogleKnowledgeGraph.py
File metadata and controls
34 lines (27 loc) · 840 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
import json
import urllib3
import requests
#Retrieving api service key and service url
config = json.load(open('config/GoogleKnowledgeGraphSettings.json'))
#Setting up the connection
http = urllib3.PoolManager()
api_key = config['api_key']
service_url = config['service_url']
#The query and its parameters
#query = 'Springfield+Armory'
query = 'browning+shooting'
params = {
'query': query,
'limit': 15,
'indent': True,
'key': api_key,
}
url = service_url + '?' + urllib3.request.urlencode(params)
print(url)
#response = json.loads(str(http.request('GET', url).read())
response = (requests.get(url).text)
#result = (response).decode('utf-8')
print(response)
jresponse = json.loads(response)
for element in jresponse['itemListElement']:
print (element['result']['name'] + ' (' + str(element['resultScore']) + ')')