f | import sys | f | import sys |
| if len(sys.argv) > 1: | | if len(sys.argv) > 1: |
n | with open(sys.argv[1], 'rb') as file: | n | with open(sys.argv[1], 'rb') as f: |
| data = file.read() | | data = f.read() |
| else: | | else: |
| data = sys.stdin.buffer.read() | | data = sys.stdin.buffer.read() |
n | encodings = ['KOI8-R', 'CP1251', 'MACCYRILLIC', 'CP866', 'ISO-8859-5', ' | n | available_encodings = ['KOI8-R', 'CP1251', 'MACCYRILLIC', 'CP866', 'ISO- |
| CP855'] | | 8859-5', 'CP855'] |
| found = False | | fl = False |
| for decode_enc in encodings: | | for src_encoding in available_encodings: |
| for intermediate_enc in encodings: | | for temp_encoding in available_encodings: |
| for final_enc in encodings: | | for dest_encoding in available_encodings: |
| try: | | try: |
n | step1 = data.decode(decode_enc) | n | intermediate_text = data.decode(src_encoding) |
| step2 = step1.encode(intermediate_enc) | | encoded_temp = intermediate_text.encode(temp_encoding) |
| result = step2.decode(final_enc) | | final_text = encoded_temp.decode(dest_encoding) |
| if 'Зимбабве' in result: | | if 'Зимбабве' in final_text: |
| print(result) | | print(final_text) |
| found = True | | fl = True |
| break | | break |
| except (UnicodeDecodeError, UnicodeEncodeError): | | except (UnicodeDecodeError, UnicodeEncodeError): |
| continue | | continue |
n | if found: | n | if fl: |
| break | | break |
n | if found: | n | if fl: |
| break | | break |
t | if not found: | t | if not fl: |
| print('Подходящий текст не найден.') | | print('Не удалось найти подходящий текст.') |