mirror of
https://github.com/intari/search2_chatgpt.git
synced 2025-09-01 18:19:39 +00:00
Fix encoding to UTF-8
This commit is contained in:
parent
158ab589a5
commit
c7ea5036a0
2 changed files with 51 additions and 0 deletions
22
check_encoding.py
Normal file
22
check_encoding.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import os
|
||||
import chardet
|
||||
|
||||
DIRECTORY = "./" # Замени на путь к папке с файлами
|
||||
|
||||
def detect_encoding(filename):
|
||||
with open(filename, "rb") as f:
|
||||
raw_data = f.read()
|
||||
result = chardet.detect(raw_data)
|
||||
return result["encoding"]
|
||||
|
||||
def check_all_files(directory):
|
||||
for root, _, files in os.walk(directory):
|
||||
for file in files:
|
||||
filepath = os.path.join(root, file)
|
||||
encoding = detect_encoding(filepath)
|
||||
if encoding and "utf-16" in encoding.lower():
|
||||
print(f"❌ {filepath} - {encoding}")
|
||||
|
||||
print("🔍 Поиск файлов с UTF-16...")
|
||||
check_all_files(DIRECTORY)
|
||||
print("✅ Готово!")
|
29
fix_encoding.py
Normal file
29
fix_encoding.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
import chardet
|
||||
import codecs
|
||||
|
||||
DIRECTORY = "./local_files" # Путь к папке с файлами
|
||||
|
||||
def convert_to_utf8(filename):
|
||||
with open(filename, "rb") as f:
|
||||
raw_data = f.read()
|
||||
result = chardet.detect(raw_data)
|
||||
encoding = result["encoding"]
|
||||
|
||||
if encoding and "utf-16" in encoding.lower():
|
||||
print(f"🔄 Конвертирую {filename} ({encoding}) в UTF-8...")
|
||||
with codecs.open(filename, "r", encoding=encoding) as f:
|
||||
content = f.read()
|
||||
with codecs.open(filename, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
print(f"✅ {filename} теперь в UTF-8!")
|
||||
|
||||
def fix_all_files(directory):
|
||||
for root, _, files in os.walk(directory):
|
||||
for file in files:
|
||||
filepath = os.path.join(root, file)
|
||||
convert_to_utf8(filepath)
|
||||
|
||||
print("🔍 Исправление кодировки...")
|
||||
fix_all_files(DIRECTORY)
|
||||
print("✅ Готово!")
|
Loading…
Add table
Reference in a new issue