dict_dl/t.py
2022-07-15 11:16:05 +00:00

37 lines
1.1 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_MWThesaurus/{prefix}_MWT.json"))
print(f"||||||||{query}||||||||")
print()
for k, v in d[query].items():
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)