40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""Упрощяет копипасту из отчётов с поломанной кодировкой"""
|
||
|
||
|
||
def fix_encoding(text):
|
||
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("ї", ">>")
|
||
fixed_text = fixed_text.replace("\x16", "--")
|
||
fixed_text = fixed_text.replace("\x10", "<<")
|
||
fixed_text = fixed_text.replace("\x11", ">>")
|
||
return fixed_text
|
||
|
||
|
||
if __name__ == "__main__":
|
||
while True:
|
||
print("Введите искажённый текст и нажмите enter:")
|
||
|
||
text_lines = []
|
||
while True:
|
||
line = input()
|
||
if line == "":
|
||
# Если строка пустая, это означает, что пользователь сделал
|
||
# двойной перенос строки.
|
||
break
|
||
text_lines.append(line)
|
||
|
||
corrupted_text = "\n".join(text_lines)
|
||
|
||
print()
|
||
print(fix_encoding(corrupted_text))
|
||
print()
|