Try utf-16 if utf-8 fails

This commit is contained in:
Dustin Pianalto 2018-05-09 16:44:25 -08:00
parent 530367b64e
commit bf55856f94

View File

@ -118,10 +118,11 @@ def process_files(z) -> (ConfigParser, ConfigParser, list):
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
print(e) print(e)
try: try:
with open(f'{path}{filename}', 'w+b') as file: with open(f'{path}{filename}', 'rb') as file:
contents = file.read() contents = file.read()
file.write(contents.decode('utf-16-le').encode('utf-8')) with open(f'{path}utf8{filename}', 'wb') as f:
with open(f'{path}{filename}', encoding='utf-8') as file: f.write(contents.decode('utf-16-le').encode('utf-8'))
with open(f'{path}utf8{filename}', encoding='utf-8') as file:
dino_data[filename] = process_file(file, 'dino.ini') dino_data[filename] = process_file(file, 'dino.ini')
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
print(e) print(e)