Skip to content

Commit

Permalink
presenting possible words for no translation
Browse files Browse the repository at this point in the history
  • Loading branch information
mebaysan committed Sep 29, 2022
1 parent 79494e6 commit f99340f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tureng_cli/commands/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
extract_translate_table_headers,
extract_translate_table_rows,
check_is_there_translation_result,
extract_translate_no_translation_header_text
extract_translate_no_translation_header_text,
extract_translate_no_translation_possible_words,
)


Expand All @@ -27,7 +28,6 @@ def translate(word, n_result):
target_url = get_turkish_translate_url(word)
res = requests.get(target_url, headers=CRACKER_HEADER)
soup = BeautifulSoup(res.text, "html.parser")


if check_is_there_translation_result(soup):
header_text = extract_translate_header_text(soup)
Expand All @@ -40,5 +40,6 @@ def translate(word, n_result):
click.echo("\n".join(table_rows_texts[:n_result]))
else:
header_text = extract_translate_no_translation_header_text(soup)
possible_words_list = extract_translate_no_translation_possible_words(soup)
click.echo(header_text)

click.echo(possible_words_list)
10 changes: 9 additions & 1 deletion tureng_cli/utilities/translate/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ def extract_translate_no_translation_header_text(soup):
# get header text
header = soup.find("h1")
header_text = "".join([i for i in header.strings])
return header_text
return header_text


def extract_translate_no_translation_possible_words(soup):
# get possible list
possible_list = soup.find("ul", {"class": "suggestion-list"})
possible_words = possible_list.find_all('a')
possible_words_list = "\n".join([word.string for word in possible_words])
return possible_words_list

0 comments on commit f99340f

Please sign in to comment.