dict_dl/d.py
2022-11-15 11:41:33 +00:00

37 lines
1.2 KiB
Python
Executable File

#!/bin/python
import os
import sys
from itertools import zip_longest
from rich.console import Console
from rich.table import Table
from dict_dl import DictFile
if len(sys.argv) < 2:
query = next(sys.stdin).strip()
else:
query = sys.argv[1].strip()
prefix = query[:3]
d = DictFile(os.path.expandvars(f"$DICT_DL/en_MerriamWebster/{prefix}_MW.json"))
print(f"||||||||{query}||||||||")
for k, v in d[query].items():
print(k,v)
# if k != "type":
# table = Table(title=k)
# table.add_column("synonyms", justify="center", style="cyan", no_wrap=True)
# table.add_column("near synonyms", justify="center", style="cyan", no_wrap=True)
# table.add_column("near antonyms", justify="center", style="cyan", no_wrap=True)
# table.add_column("antonyms", justify="center", style="cyan", no_wrap=True)
# syns = v["synonyms"]
# nsyns = v["related" if "related" in v else "near synonyms"]
# ants = v["near antonyms"]
# nants = v["antonyms"]
# for s, ns, na, a in zip_longest(syns, nsyns, nants, ants, fillvalue=""):
# table.add_row(s, ns, na, a)
# console = Console()
# console.print(table)