-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjisho.py
More file actions
executable file
·42 lines (28 loc) · 1.46 KB
/
jisho.py
File metadata and controls
executable file
·42 lines (28 loc) · 1.46 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
#!/usr/bin/env python3
import json
import requests
def lookup(query):
data = json.loads(requests.get(
"http://jisho.org/api/v1/search/words?keyword=%s" % query).text)
results = {}
for result in range(len(data["data"])):
results[result] = {"readings": [], "words": [], "senses": {}}
for a in range(len(data["data"][result]["japanese"])):
if (data["data"][result]["japanese"][a]["reading"] not
in results[result]["readings"]):
results[result]["readings"].append(
data["data"][result]["japanese"][a]["reading"])
if (data["data"][result]["japanese"][a]["word"] not
in results[result]["words"]):
results[result]["words"].append(
data["data"][result]["japanese"][a]["word"])
for b in range(len(data["data"][result]["senses"])):
results[result]["senses"][b] = \
{"english": [], "parts": []}
for c in range(len(data["data"][result]["senses"][b]["english_definitions"])):
results[result]["senses"][b]["english"].append(
data["data"][result]["senses"][b]["english_definitions"][c])
for d in range(len(data["data"][result]["senses"][b]["parts_of_speech"])):
results[result]["senses"][b]["parts"].append(
data["data"][result]["senses"][b]["parts_of_speech"][d])
return results