mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-09-16 07:40:16 +02:00
Replace sanitize_filename with safe_name
This commit is contained in:
@@ -12,9 +12,9 @@ import importlib.metadata
|
|||||||
from Whatsapp_Chat_Exporter import android_crypt, exported_handler, android_handler
|
from Whatsapp_Chat_Exporter import android_crypt, exported_handler, android_handler
|
||||||
from Whatsapp_Chat_Exporter import ios_handler, ios_media_handler
|
from Whatsapp_Chat_Exporter import ios_handler, ios_media_handler
|
||||||
from Whatsapp_Chat_Exporter.data_model import ChatCollection, ChatStore
|
from Whatsapp_Chat_Exporter.data_model import ChatCollection, ChatStore
|
||||||
from Whatsapp_Chat_Exporter.utility import APPLE_TIME, CLEAR_LINE, Crypt, check_update, DbType
|
from Whatsapp_Chat_Exporter.utility import APPLE_TIME, CLEAR_LINE, Crypt, check_update
|
||||||
from Whatsapp_Chat_Exporter.utility import readable_to_bytes, sanitize_filename
|
from Whatsapp_Chat_Exporter.utility import readable_to_bytes, safe_name, bytes_to_readable
|
||||||
from Whatsapp_Chat_Exporter.utility import import_from_json, incremental_merge, bytes_to_readable
|
from Whatsapp_Chat_Exporter.utility import import_from_json, incremental_merge, DbType
|
||||||
from argparse import ArgumentParser, SUPPRESS
|
from argparse import ArgumentParser, SUPPRESS
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
@@ -683,7 +683,7 @@ def export_multiple_json(args, data: Dict) -> None:
|
|||||||
else:
|
else:
|
||||||
contact = jik.replace('+', '')
|
contact = jik.replace('+', '')
|
||||||
|
|
||||||
with open(f"{json_path}/{sanitize_filename(contact)}.json", "w") as f:
|
with open(f"{json_path}/{safe_name(contact)}.json", "w") as f:
|
||||||
file_content = json.dumps(
|
file_content = json.dumps(
|
||||||
{jik: data[jik]},
|
{jik: data[jik]},
|
||||||
ensure_ascii=not args.avoid_encoding_json,
|
ensure_ascii=not args.avoid_encoding_json,
|
||||||
|
|||||||
@@ -334,18 +334,6 @@ def incremental_merge(source_dir: str, target_dir: str, media_dir: str, pretty_p
|
|||||||
shutil.copy2(source_file, target_file)
|
shutil.copy2(source_file, target_file)
|
||||||
|
|
||||||
|
|
||||||
def sanitize_filename(file_name: str) -> str:
|
|
||||||
"""Sanitizes a filename by removing invalid and unsafe characters.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
file_name: The filename to sanitize.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The sanitized filename.
|
|
||||||
"""
|
|
||||||
return "".join(x for x in file_name if x.isalnum() or x in "- ")
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_name(contact: str, chat: ChatStore) -> Tuple[str, str]:
|
def get_file_name(contact: str, chat: ChatStore) -> Tuple[str, str]:
|
||||||
"""Generates a sanitized filename and contact name for a chat.
|
"""Generates a sanitized filename and contact name for a chat.
|
||||||
|
|
||||||
@@ -375,7 +363,7 @@ def get_file_name(contact: str, chat: ChatStore) -> Tuple[str, str]:
|
|||||||
else:
|
else:
|
||||||
name = phone_number
|
name = phone_number
|
||||||
|
|
||||||
return sanitize_filename(file_name), name
|
return safe_name(file_name), name
|
||||||
|
|
||||||
|
|
||||||
def get_cond_for_empty(enable: bool, jid_field: str, broadcast_field: str) -> str:
|
def get_cond_for_empty(enable: bool, jid_field: str, broadcast_field: str) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user