Skip to content

Commit 83f621d

Browse files
author
Gökçe
committed
v0.2.1
1 parent ea6b0fa commit 83f621d

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
requires = [line.strip() for line in file.readlines()]
99

1010
VERSION = m.__version__
11-
DESCRIPTION = "Command-line tool for TDK Dictionary (sozluk.gov.tr) with rich output."
11+
DESCRIPTION = "Command-line tool for TDK Dictionary, sozluk.gov.tr with rich output."
1212

1313
setup(
1414
name="tdk-cli",
1515
version=VERSION,
16-
url="https://github.com/agmmnn/turengcli",
16+
url="https://github.com/agmmnn/tdk-cli",
1717
description=DESCRIPTION,
1818
long_description=long_description,
1919
long_description_content_type="text/markdown",

tdk_cli/__main__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .cli import TDKDict
22
import argparse
33

4-
__version__ = "0.0.1"
4+
__version__ = "0.2.1"
55

66
# parse arguments
77
ap = argparse.ArgumentParser()
@@ -16,14 +16,7 @@
1616
"--plain",
1717
action="store_true",
1818
default=False,
19-
help="returns plain text output",
20-
)
21-
ap.add_argument(
22-
"-f",
23-
"--fuzzy",
24-
action="store_true",
25-
default=False,
26-
help="returns fuzzy search results",
19+
help="returns plain text output.",
2720
)
2821
ap.add_argument("-v", "--version", action="version", version="%(prog)s v" + __version__)
2922
args = ap.parse_args()
@@ -32,7 +25,7 @@
3225
def cli():
3326
word = " ".join(args.word)
3427
if word == "":
35-
print("Please enter a word.")
28+
print("Kelime giriniz...")
3629
else:
3730
if args.plain:
3831
TDKDict(word).plain()

tdk_cli/cli.py

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from urllib.parse import quote
3-
from urllib.request import urlopen
3+
from urllib.request import Request, urlopen
44
from json import loads
55

66
from rich import box
77
from rich.table import Table
8-
from rich.console import Console
98
from rich import print
109

1110

@@ -14,25 +13,63 @@ def __init__(self, word):
1413
self.word = word
1514
# gts, bati, tarama, derleme, atasozu, kilavuz, lehceler
1615
url = "https://sozluk.gov.tr/gts?ara=" + quote(word)
17-
self.data = loads(urlopen(url).read())
16+
req = Request(url, headers={"User-Agent": "Mozilla/5.0"})
17+
self.data = loads(urlopen(req).read())
18+
# print(self.data)
1819
if "error" in self.data:
19-
print("Error")
20+
print(self.data["error"])
2021
exit()
2122

2223
def rich(self):
2324
data = self.data
2425
word = self.word
25-
table = Table(title=word + " - TDK", show_header=False, box=box.SQUARE)
2626
for i in range(len(data)):
27+
table = Table(
28+
box=box.ROUNDED,
29+
show_footer=(
30+
True
31+
if ("atasozu" in data[i]) or (data[i]["birlesikler"] != None)
32+
else False
33+
),
34+
footer_style="grey62",
35+
)
36+
table.add_column(
37+
"[cyan]❯ "
38+
+ data[i]["madde"]
39+
+ (
40+
" (" + data[i]["anlam_gor"] + ")"
41+
if (len(data) > 1 and data[i]["anlam_gor"] != "0")
42+
else ""
43+
)
44+
+ "[/cyan]",
45+
(
46+
(
47+
"Atasözleri, Deyimler veya Birleşik Fiiller:\n"
48+
+ str([i["madde"] for i in data[i]["atasozu"]])[1:-1]
49+
if "atasozu" in data[i]
50+
else ""
51+
)
52+
+ (
53+
"\n\n"
54+
if ("atasozu" in data[i]) and (data[i]["birlesikler"] != None)
55+
else ""
56+
)
57+
+ (
58+
("Birleşik Kelimeler:\n") + data[i]["birlesikler"]
59+
if data[i]["birlesikler"] != None
60+
else ""
61+
)
62+
),
63+
)
2764
# lang
2865
if data[i]["lisan"] != "":
29-
table.add_row(data[i]["lisan"] + ":")
66+
table.add_row(data[i]["lisan"])
3067
else:
3168
# suffix
3269
if data[i]["taki"] != None:
33-
table.add_row(word + ", " + data[i]["taki"] + ":")
34-
else:
35-
table.add_row(word + ":")
70+
table.add_row(word + ", " + data[i]["taki"])
71+
elif (data[i]["telaffuz"] != None) and (data[i]["ozel_mi"] == "1"):
72+
table.add_row("özel, " + data[i]["telaffuz"])
3673
for j in range(len(data[i]["anlamlarListe"])):
3774
# meaning
3875
table.add_row(
@@ -47,9 +84,9 @@ def rich(self):
4784
+ "”"
4885
)
4986
# space after each item except last one
50-
if len(data) > 1 and i != range(len(data))[1]:
51-
table.add_row("")
52-
print(table)
87+
# if len(data) > 1 and i != range(len(data))[1]:
88+
# table.add_row("")
89+
print(table)
5390

5491
def plain(self):
5592
data = self.data

0 commit comments

Comments
 (0)