Finished Kanji search

This commit is contained in:
Robert 2020-08-11 18:31:20 +02:00
parent 67b50c3b8c
commit 68bf4ccba5
2 changed files with 17 additions and 6 deletions

View file

@ -38,11 +38,13 @@ class Kanji(commands.Cog):
)
if node.kun:
embed.add_field(name="Kun", value=", ".join(node.kun), inline=False)
embed.add_field(name="Kun", value=" ".join(node.kun), inline=False)
if node.on:
embed.add_field(name="On", value=", ".join(node.on), inline=False)
embed.add_field(name="On", value=" ".join(node.on), inline=False)
embed.set_footer(text=f"{self.activeObject.page + 1}/{self.activeObject.total_pages}")
embed.add_field(name=f"Radical: {node.radical[0]}", value=node.radical[1], inline=False)
embed.set_footer(text=f"Jōyō kanji (Grade {node.grade}) | JLPT level {node.jlpt}\t\t{self.activeObject.page + 1}/{self.activeObject.total_pages}")
return embed

View file

@ -1,6 +1,7 @@
import requests
import urllib.parse
import json
import re
from bs4 import BeautifulSoup
TEMPLATE_URL = "https://jisho.org/api/v1/search/words?keyword={0}"
@ -90,7 +91,7 @@ class JishoKanjiNode():
self.meaning = ""
self.kun = []
self.on = []
self.radical = ""
self.radical = []
self.grade = ""
self.jlpt = ""
@ -144,6 +145,14 @@ class JishoKanji():
self.nodes[-1].on.append(reading.string)
# Radical
radical_block = readings_block.findChild("div", {"class": "radicals"}, recursive=True)
print(radical_block)
radical_block = info.findChild("div", {"class": "radicals"}, recursive=True).findChild("span")
self.nodes[-1].radical.append(re.sub(r'[ \n"]', "", radical_block.contents[2].string))
self.nodes[-1].radical.append(re.sub(r'[ \n"]', "", radical_block.contents[1].string))
# JLPT/Grade info
grade_block = info.findChild("div", {"class": "grade"}, recursive=True)
if grade_block != None:
self.nodes[-1].grade = grade_block.findChild("strong").string[-1]
self.nodes[-1].jlpt = info.findChild("div", {"class": "jlpt"}, recursive=True).findChild("strong").string