-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynonyms.py
51 lines (34 loc) · 1.11 KB
/
synonyms.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
#Create an API
# https://store.apicultur.io:9443/apis/info?name=SinonimosPorPalabra&version=1.0.0&provider=molinodeideas
# http://stackoverflow.com/questions/29931671/making-an-api-call-in-python-with-an-api-that-requires-a-bearer-token
#curl -H "Authorization: Bearer f7JE_2svUVwP5ARGfw8aQhnLXlga" 'http://store.apicultur.com/api/sinonimosporpalabra/1.0.0/beso'
import requests
import sys
class Synonyms(object):
def __init__(self, api, authorization):
self.api = api
self.authorization = authorization
def get(self, word):
query = self.api + word
print(query)
token = 'Bearer ' + self.authorization
print(token)
resp = requests.get(query,
headers={'Authorization': token})
try:
json_list = resp.json()
results = []
for i in json_list:
value = i['valor']
results.append(value)
except:
results = []
return results
if __name__ == '__main__':
API = 'http://store.apicultur.com/api/sinonimosporpalabra/1.0.0/'
KEY = 'f7JE_2svUVwP5ARGfw8aQhnLXlga'
c = Synonyms(API, KEY)
result_1 = query.get("beso")
print(result_1)
result_2 = query.get("comida")
print(result_2)