Glossary return function
This commit is contained in:
parent
a2aa209182
commit
4b2cf5d0fa
|
|
@ -76,6 +76,19 @@ KANJI_RE = re.compile(r"[\u4E00-\u9FFF]")
|
||||||
with open("dump-vocab.json", "r", encoding="utf-16") as f:
|
with open("dump-vocab.json", "r", encoding="utf-16") as f:
|
||||||
vocab = json.load(f)
|
vocab = json.load(f)
|
||||||
|
|
||||||
|
def get_glossary(word :str) -> list:
|
||||||
|
glossary = list()
|
||||||
|
dict_items = term_entries(word)
|
||||||
|
|
||||||
|
entry = next(iter(dict_items.get("dictionaryEntries",[])),None)
|
||||||
|
if entry:
|
||||||
|
definition = next(iter(entry.get("definitions",[])),None)
|
||||||
|
if definition:
|
||||||
|
def_entry = next(iter(definition.get("entries", [])),None)
|
||||||
|
if def_entry:
|
||||||
|
glossary.extend( list(extract_text_by_type(def_entry, "glossary")) )
|
||||||
|
return glossary[:2]
|
||||||
|
|
||||||
for item in vocab:
|
for item in vocab:
|
||||||
#print(word[0])
|
#print(word[0])
|
||||||
word = item[0]
|
word = item[0]
|
||||||
|
|
@ -87,21 +100,6 @@ for item in vocab:
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(elide(response.text))
|
# print(elide(response.text))
|
||||||
# print(response.json()) # Dumps json
|
# print(response.json()) # Dumps json
|
||||||
dict_items = term_entries(word)
|
|
||||||
# for dic in dict_items['dictionaryEntries']:
|
|
||||||
# print(dic)
|
|
||||||
## Recurssive content -> data pipelines
|
|
||||||
print(word)
|
|
||||||
glossary = list()
|
|
||||||
|
|
||||||
entry = next(iter(dict_items.get("dictionaryEntries",[])),None)
|
|
||||||
if entry:
|
|
||||||
definition = next(iter(entry.get("definitions",[])),None)
|
|
||||||
if definition:
|
|
||||||
def_entry = next(iter(definition.get("entries", [])),None)
|
|
||||||
if def_entry:
|
|
||||||
glossary.extend( list(extract_text_by_type(def_entry, "glossary")) )
|
|
||||||
glossary[:2]
|
|
||||||
# for entry in dict_items.get("dictionaryEntries", []):
|
# for entry in dict_items.get("dictionaryEntries", []):
|
||||||
# for definition in entry.get("definitions", []):
|
# for definition in entry.get("definitions", []):
|
||||||
# first = next(iter(definition.get("entries", [])),None)
|
# first = next(iter(definition.get("entries", [])),None)
|
||||||
|
|
@ -117,7 +115,7 @@ for item in vocab:
|
||||||
# print(data['content']) # type of content
|
# print(data['content']) # type of content
|
||||||
|
|
||||||
#anki_card = anki_fields_term(word)
|
#anki_card = anki_fields_term(word)
|
||||||
item.append("; ".join(glossary))
|
item.append("; ".join(get_glossary(word)))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
with open("dump-vocab.json", "w", encoding="utf-16") as outfile:
|
with open("dump-vocab.json", "w", encoding="utf-16") as outfile:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user