59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# All rights reserved.
|
|
|
|
"""
|
|
CSV Processing helper for AI operations.
|
|
Handles CSV content processing with options.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Dict, Any
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class CsvProcessingHelper:
|
|
"""Helper for CSV processing operations"""
|
|
|
|
def __init__(self, methodInstance):
|
|
"""
|
|
Initialize CSV processing helper.
|
|
|
|
Args:
|
|
methodInstance: Instance of MethodAi (for access to services)
|
|
"""
|
|
self.method = methodInstance
|
|
self.services = methodInstance.services
|
|
|
|
def applyCsvOptions(self, csvContent: str, options: Dict[str, Any]) -> str:
|
|
"""
|
|
Apply CSV processing options to CSV content.
|
|
|
|
Args:
|
|
csvContent: CSV content as string
|
|
options: Dictionary with CSV processing options
|
|
|
|
Returns:
|
|
Processed CSV content as string
|
|
"""
|
|
if not csvContent:
|
|
return csvContent
|
|
|
|
# Apply options if provided
|
|
if options:
|
|
# Handle delimiter option
|
|
if "delimiter" in options:
|
|
delimiter = options["delimiter"]
|
|
# Replace delimiter in content (simple approach)
|
|
# Note: This is a basic implementation, may need enhancement
|
|
if delimiter != ",":
|
|
csvContent = csvContent.replace(",", delimiter)
|
|
|
|
# Handle quote character option
|
|
if "quotechar" in options:
|
|
quotechar = options["quotechar"]
|
|
# Replace quote character (simple approach)
|
|
if quotechar != '"':
|
|
csvContent = csvContent.replace('"', quotechar)
|
|
|
|
return csvContent
|
|
|