-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlinux_dict.py
More file actions
81 lines (71 loc) · 1.84 KB
/
Copy pathlinux_dict.py
File metadata and controls
81 lines (71 loc) · 1.84 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import requests
from urllib.parse import urlencode
import re
import sys
def strprint(string_):
string_ = re.sub('{bc}', ': ', string_)
string_ = re.sub('{ldquo}', '"', string_)
string_ = re.sub('{rdquo}', '"', string_)
string_ = re.sub("{([^{])*}", "", string_)
print(string_)
def print_meaning(res):
#differnt verb dividers
for dicts in res['def']:
#different sn's
for lists in dicts['sseq']:
try:
if(lists[0][0] != 'sense'):
continue
except:
continue
for l in lists[0][1]['dt']:
if l[0] == 'text':
strprint(l[1])
else:
continue
print('Short Defination: ')
for sdef in res['shortdef']:
strprint(sdef)
def get_meaning(word='welcome', flag = 0):
url = 'https://dictionaryapi.com/api/v3/references/sd2/json/'+word+'?key=880ce8f2-178b-40a5-a675-6862884fd925'
try:
response = requests.get(url)
except:
print('Error in fetching the results, check your connectivity')
return
result = response.json()
if response.status_code != 200:
print('Something went wrong: HTTP Error Code: %d' %(response.status_code))
return
try:
if type(result[0]) == str:
kjj = 1
except:
print('Sorry!')
return
if type(result[0]) == str:
if (flag == 1 or len(result) == 0):
print('Sorry, we did not find any meaning matching your word')
return
print('Did you mean following words? Enter the number of word that you want to search')
for i, res in enumerate(result):
print('%d. '%(i+1) + res)
i = int(input().split()[0])
try:
word = result[i - 1]
get_meaning(word, flag = 1)
return
except:
print('Enter Valid Choice')
return
for res in result:
print(' ')
print(' ')
print(' ')
print_meaning(res)
#word = input('Enter the word you want to search: ')
word = " ".join(sys.argv[1:])
if(len(sys.argv) <= 1):
print('Please provide the word to be searched')
else:
get_meaning(word)