Csv To Vcf [extra Quality] Direct

def read_csv(self, file_path: str, encoding: Optional[str] = None) -> List[Dict]: """Read CSV file and return list of dictionaries""" if not encoding: encoding = self.detect_encoding(file_path) print(f"Detected encoding: encoding") contacts = [] try: with open(file_path, 'r', encoding=encoding) as f: # Detect delimiter sample = f.read(1024) f.seek(0) delimiter = self.detect_delimiter(sample) print(f"Detected delimiter: delimiter") reader = csv.DictReader(f, delimiter=delimiter) # Normalize column names reader.fieldnames = [self.normalize_column_name(col) for col in reader.fieldnames] for row_num, row in enumerate(reader, start=2): contact = self.normalize_contact(row) if contact.get('name') or contact.get('phone'): contacts.append(contact) else: print(f"Warning: Row row_num skipped - missing name or phone") except Exception as e: raise Exception(f"Error reading CSV file: str(e)") return contacts

# Check if input file exists if not os.path.exists(args.input): print(f"Error: Input file 'args.input' not found") return 1 csv to vcf

def add_photo(self, contact: Dict, photo_path: str) -> str: """Add photo to vCard (base64 encoded)""" import base64 with open(photo_path, 'rb') as f: photo_data = base64.b64encode(f.read()).decode('utf-8') return f"PHOTO;ENCODING=b;TYPE=JPEG:photo_data" encoding: Optional[str] = None) -&gt

def test_basic_conversion(self): csv_content = """Name,Phone,Email John Doe,+1234567890,john@test.com""" row in enumerate(reader

def escape_vcf_text(self, text: str) -> str: """Escape special characters for VCF format""" if not text: return "" # VCF escaping rules text = text.replace('\\', '\\\\') text = text.replace(';', '\\;') text = text.replace(',', '\\,') text = text.replace('\n', '\\n') text = text.replace('\r', '') return text