Embed done

This commit is contained in:
Robert 2020-08-11 13:11:46 +02:00
parent 88d7ea0ac4
commit 86986f977b
2 changed files with 64 additions and 4 deletions

View file

@ -7,20 +7,39 @@ TEMPLATE_URL = "https://jisho.org/api/v1/search/words?keyword={0}"
class JishoSenses():
def __init__(self, sense):
self.english_definitions = sense["english_definitions"]
self.english_definitions_formatted = "; ".join(self.english_definitions)
self.fenglish_definitions = "; ".join(self.english_definitions)
self.parts_of_speech = sense["parts_of_speech"]
self.fparts_of_speech = ", ".join(sense["parts_of_speech"])
if self.fparts_of_speech == "":
self.fparts_of_speech = "\u200b" # Zero width space to have empty embed value
class JishoNode():
def __init__(self, node):
self.slug = node["slug"]
self.is_common = node["is_common"]
if "is_common" in node:
self.is_common = node["is_common"]
else:
self.is_common = False
self.tags = node["tags"]
self.jlpt = node["jlpt"]
self.ftags = ""
if self.is_common:
self.ftags += "Common "
for tag in self.tags:
self.ftags += f"| {tag} "
for jlpt in self.jlpt:
self.ftags += f"| {jlpt} "
self.japanese = []
for entry in node["japanese"]:
if "word" not in entry:
word = entry["reading"]
reading = ""
elif "reading" not in entry:
word = entry["word"]
reading = ""
else:
word = entry["word"]
reading = entry["reading"]