-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI is improved to handle exceptions that occur during the translatio…
…n phase
- Loading branch information
Showing
5 changed files
with
76 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ def bind_commands_to_cli(cli, *args, **kwargs): | |
|
||
def get_turkish_translate_url(word): | ||
return BASE_URL_TR + word | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
def extract_translate_header_text(soup): | ||
# get header text | ||
header = soup.find("h2") | ||
header_text = "".join([i for i in header.strings]) | ||
return header_text | ||
|
||
|
||
def extract_translate_table_headers(soup): | ||
# get table | ||
table = soup.find_all("table")[0] | ||
rows = table.find_all("tr") | ||
|
||
# handle header row | ||
table_header = rows[0] | ||
|
||
# table header | ||
table_headers = table_header.find_all("th") | ||
table_id = "#" | ||
table_category = table_headers[1].string | ||
table_turkish = table_headers[2].string | ||
table_english = table_headers[3].string | ||
table_header_text = " \t".join( | ||
[table_id, table_category, table_turkish, table_english] | ||
) | ||
return table_header_text | ||
|
||
|
||
def extract_translate_table_rows(soup): | ||
# get table | ||
table = soup.find_all("table")[0] | ||
rows = table.find_all("tr") | ||
|
||
# handle result rows | ||
table_rows = rows[1:] | ||
|
||
# table rows | ||
table_rows_texts = [] | ||
for table_row in table_rows: | ||
row_columns = table_row.find_all("td") | ||
if len(row_columns) >= 4: | ||
row_id = row_columns[0].string | ||
row_category = row_columns[1].string | ||
row_turkish = row_columns[2].find_all("a")[0].string | ||
row_english = row_columns[3].find_all("a")[0].string | ||
row_text = "\t+ ".join([row_id, row_category, row_turkish, row_english]) | ||
table_rows_texts.append(row_text) | ||
|
||
return table_rows_texts | ||
|
||
|
||
def check_is_there_translation_result(soup): | ||
# get header text | ||
result = soup.find_all("table", class_="searchResultsTable") | ||
return True if len(result) >= 1 else False |