diff --git a/decode.py b/decode.py index 1a4001e..a55ece0 100644 --- a/decode.py +++ b/decode.py @@ -2,7 +2,14 @@ def fix_encoding(text): - fixed_text = text.encode("latin1").decode("windows-1251") + result = [] + for ch in text: + try: + decoded = ch.encode("latin1").decode("windows-1251") + result.append(decoded) + except (UnicodeEncodeError, UnicodeDecodeError): + result.append(ch) + fixed_text = "".join(result) fixed_text = fixed_text.replace("ј", "ё") fixed_text = fixed_text.replace("ѕ", "<<") fixed_text = fixed_text.replace("ї", ">>")