Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Anki integration with Jisho.org and more #49

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bae1847
Add sentence translation when adding a card to Anki
carloscheddar May 9, 2023
86fa25e
Show translation in Anki Card
carloscheddar May 10, 2023
03c59a6
Allow parsing dictionaries with structured-content
carloscheddar May 10, 2023
5eeb34c
Move anki methods to ankicard file instead of logs
carloscheddar May 11, 2023
be4e19e
Show a list of definitions in the glosarry card instead of the first one
carloscheddar May 13, 2023
081648a
Sort and filter dictionary entries based on frequency and sequence
carloscheddar May 13, 2023
48c1c1b
Remove other forms from the glossary section
carloscheddar May 14, 2023
7683cc9
Refactor playWordAudio to use already generated audio_url
carloscheddar May 15, 2023
98140e8
Add method to fetch dictionaries from jisho.org
carloscheddar May 15, 2023
8384b95
Update look_up_dictionary to return an array with dictionaries and ji…
carloscheddar May 15, 2023
bea4209
Add getDictionaries method to consolidate dictionary ordering and fil…
carloscheddar May 15, 2023
a1902ed
Change addLoadAudioIfExists to use getDictionaries
carloscheddar May 15, 2023
d3d3365
Fix issue where some jisho entries would not have a `word` key
carloscheddar May 16, 2023
2aeb977
Update sortDicts to prefer entries with both headword and reading
carloscheddar May 16, 2023
36ea401
Show parts of speech above definitions if they exist
carloscheddar May 16, 2023
2522cfa
Convert reading to hiragana when fetching audio
carloscheddar May 17, 2023
19f30d0
If audio is not found retry without the kanji param
carloscheddar May 17, 2023
a2f9ad8
Read/Write to prefer jisho toggle on Anki settings page
carloscheddar May 17, 2023
1dc3b25
Use a copy of the dicts array when sorting
carloscheddar May 24, 2023
8bdd57c
Use reading as head word for jisho if head word is not found
carloscheddar May 29, 2023
b0e5bd4
Prioritize items with tags when sorting glossary entries
carloscheddar May 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,40 @@ def look_up(word):
} for entry in dictionary_map[word]]
return result

def look_up_jisho(word):
url = f"https://jisho.org/api/v1/search/words?keyword={word}"
response = requests.get(url)

if response.status_code == 200:
data = response.json()["data"]
dictionaries = []

# For each item in data we want to loop through the senses array and return and object that matches the current dictionaries
for item in data:
forms = []
for form in item['japanese']:
word = form.get('word', '')
reading = form.get('reading', '')
if word == '':
forms.append(f"{reading}")
else:
forms.append(f"{word}[{reading}]")
for sense in item['senses']:
reading = item['japanese'][0].get('reading', '')
dictionaries.append({
'headword': item['japanese'][0].get('word', reading),
'reading': item['japanese'][0].get('reading', ''),
'tags': ' '.join(sense['tags']),
'glossary_list': sense['english_definitions'],
'sequence': item['slug'],
'parts_of_speech': sense['parts_of_speech'],
'forms': forms,
})

return dictionaries

return None

def get_jpod_audio(url):
try:
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
Expand Down
4 changes: 2 additions & 2 deletions game2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ankiconnect import invoke, get_anki_models, update_anki_models, create_anki_note, fetch_anki_fields
from imageprofile import export_image_profile, load_image_profiles, open_image_profile
from gamescript import load_game_scripts, open_game_script
from dictionary import load_all_dictionaries, look_up, get_local_dictionaries, load_dictionary, get_jpod_audio_url
from dictionary import load_all_dictionaries, look_up, look_up_jisho, get_local_dictionaries, load_dictionary, get_jpod_audio_url
from config import r_config, r_config_all, r_config_section, w_config, APP_CONFIG, LOG_CONFIG, TEXTHOOKER_CONFIG

session_start_time = get_time_string()
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_dictionaries():

@eel.expose
def look_up_dictionary(word):
return look_up(word)
return [look_up(word), look_up_jisho(word)]

@eel.expose
def get_path_to_textractor():
Expand Down
Loading