-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoxford.py
More file actions
29 lines (23 loc) · 882 Bytes
/
oxford.py
File metadata and controls
29 lines (23 loc) · 882 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
from requests import get
from os import environ
from box import Box
base_url = 'https://od-api.oxforddictionaries.com'
headers = {'app_id': environ['app_id'],
'app_key': environ['app_key']}
def get_definition(word: str):
response = get(
'{}/api/v2/entries/en-gb/{}?strictMatch=true&fields=definitions'.format(base_url, word), headers=headers)
json = response.json()
json = Box(json)
if 'error' in json:
return False
sense = json.results[0].lexicalEntries[0].entries[0].senses[0]
return sense.definitions[0] if 'definitions' in sense else False
def get_root(word: str):
response = get(
'{}/api/v2/lemmas/en-gb/{}'.format(base_url, word), headers=headers)
json = response.json()
json = Box(json)
if 'error' in json:
return False
return json.results[0].lexicalEntries[0].inflectionOf[0].text