{"id":22801022,"url":"https://github.com/poacosta/spanish-encoding-fixer","last_synced_at":"2026-05-18T05:45:04.492Z","repository":{"id":267549898,"uuid":"901601455","full_name":"poacosta/spanish-encoding-fixer","owner":"poacosta","description":"This tool is your knight in shining armor for those encoding nightmares, in JSON and CSV! 🗡️ 🛡️","archived":false,"fork":false,"pushed_at":"2025-02-27T13:51:29.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T19:36:57.118Z","etag":null,"topics":["csv","json","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poacosta.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-11T01:01:05.000Z","updated_at":"2025-02-27T14:11:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"457c19bb-13fa-450e-8b91-51bf26c61b4f","html_url":"https://github.com/poacosta/spanish-encoding-fixer","commit_stats":null,"previous_names":["poacosta/spanish-encoding-fixer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poacosta%2Fspanish-encoding-fixer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poacosta%2Fspanish-encoding-fixer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poacosta%2Fspanish-encoding-fixer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poacosta%2Fspanish-encoding-fixer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poacosta","download_url":"https://codeload.github.com/poacosta/spanish-encoding-fixer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246367846,"owners_count":20765940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","json","python"],"created_at":"2024-12-12T08:08:44.520Z","updated_at":"2026-05-18T05:44:59.440Z","avatar_url":"https://github.com/poacosta.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spanish Encoding Fixer\n\nEver wrestled with mangled Spanish text in JSON or CSV files? You know, when your beautiful \"más allá\" turns into a horrifying \"mÃ¡s allÃ¡\"? Yeah, we've all been there. This tool is your knight in shining armor for those encoding nightmares, now with added CSV superpowers! 🗡️ 🛡️\n\n## Features\n\n- **Multiformat Support**: JSON and CSV files are both fair game now\n- **Async Processing**: Because life's too short to wait for sequential file processing\n- **Smart Format Detection**: Automatically identifies and handles different file types\n- **CSV Dialect Sniffing**: Detects delimiter, quoting style, and headers automatically\n- **Robust Error Handling**: With retries that would make a persistence hunter proud\n- **Automatic Backups**: Because we're paranoid (in a good way)\n- **Detailed Logging**: Know exactly what's happening, when, and where\n- **Type Safety**: Pydantic models keeping everything in check\n- **Progress Tracking**: Watch those files get fixed in real-time\n- **Comprehensive Validation**: No encoding issue escapes our notice\n\n## 🚀 Quick Start\n\n### Prerequisites\n\n```bash\n# Python 3.8+ required\npip install pydantic tenacity\n```\n\n### Basic Usage\n\n```python\nimport asyncio\nfrom src.spanish_encoding_fixer import SpanishEncodingFixer, FileType\n\n\nasync def main():\n    fixer = SpanishEncodingFixer(\n        input_dir=\"path/to/your/files\",\n        backup=True,\n        max_retries=3,\n        # Process both JSON and CSV files (default)\n        file_types={FileType.JSON, FileType.CSV}\n    )\n    stats = await fixer.process_directory()\n    print(f\"Processing completed in {stats.duration:.2f} seconds\")\n    print(f\"JSON files processed: {stats.json_files_processed}\")\n    print(f\"CSV files processed: {stats.csv_files_processed}\")\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### CSV-Only Mode\n\n```python\nimport asyncio\nfrom src.spanish_encoding_fixer import SpanishEncodingFixer, FileType\n\n\nasync def main():\n    # Focus only on CSV files\n    fixer = SpanishEncodingFixer(\n        input_dir=\"path/to/your/csv/files\",\n        backup=True,\n        file_types={FileType.CSV}\n    )\n    stats = await fixer.process_directory()\n    print(f\"Processed {stats.csv_files_processed} CSV files\")\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## 🔍 How It Works\n\nThe fixer employs a battle-tested strategy to handle common Spanish encoding issues:\n\n1. **Detection**: Identifies file types and problematic character sequences\n2. **Format-Specific Parsing**: Handles JSON and CSV with specialized parsers\n3. **Transformation**: Applies carefully mapped character replacements\n4. **Validation**: Verifies the results to ensure quality\n5. **Backup**: Keeps your original files safe\n6. **Reporting**: Provides detailed statistics and logs\n\n## 📊 Enhanced Processing Stats\n\nGet comprehensive statistics about your processing run:\n\n```python\nProcessingStats(\n    processed=42,  # Successfully processed files\n    failed=0,  # Failed files\n    skipped=2,  # Skipped files\n    json_files_processed=30,  # JSON files fixed\n    csv_files_processed=12,  # CSV files fixed\n    total_chars_processed=123456,  # Total characters fixed\n    duration=3.14  # Processing time in seconds\n)\n```\n\n## 🛠 Advanced Usage\n\n### Custom CSV Dialect\n\n```python\nfixer = SpanishEncodingFixer(\n    input_dir=\"data\",\n    csv_dialect=\"excel-tab\"  # Use tab-delimited dialect as fallback\n)\n```\n\n### Custom Replacement Mappings\n\n```python\nfixer = SpanishEncodingFixer(\n    input_dir=\"data\",\n    replacements={\n        'Ã¡': 'á',\n        'Ã©': 'é',\n        # Add your own mappings\n    }\n)\n```\n\n### Error Handling Configuration\n\n```python\nfrom tenacity import stop_after_attempt, wait_exponential\n\nfixer = SpanishEncodingFixer(\n    input_dir=\"data\",\n    retry_config={\n        \"stop\": stop_after_attempt(5),\n        \"wait\": wait_exponential(multiplier=1, min=4, max=10)\n    }\n)\n```\n\n## 📝 Logging\n\nThe tool provides detailed logging with rotation:\n\n```plaintext\n2024-12-11 00:41:57,115 - INFO - [main.py:182] - Processing file: data/example.json\n2024-12-11 00:41:57,116 - INFO - [main.py:223] - Successfully processed: example.json\n2024-12-11 00:41:57,220 - INFO - [main.py:182] - Processing file: data/customers.csv\n2024-12-11 00:41:57,225 - INFO - [main.py:223] - Successfully processed: customers.csv\n```\n\n## CSV-Specific Features\n\nThe CSV processor includes special handling for:\n\n- **Dialect Detection**: Automatically identifies delimiters, quote characters, and other formatting\n- **Header Preservation**: Maintains your column headers while fixing the content\n- **Row-by-Row Processing**: Handles each CSV record individually for maximum reliability\n- **Robust Error Recovery**: Gracefully handles malformed CSV data when possible\n\n## 🧪 Testing\n\nRun the test suite to ensure everything works as expected:\n\n```bash\npython -m unittest discover tests\n# Or with pytest\npython -m pytest tests/\n```\n\n## 🤝 Contributing\n\nHere's how you can help:\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## 📜 License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n## 🐛 Known Issues\n\n- Root-level JSON arrays require special handling\n- Large files (\u003e1GB) may require chunked processing\n- Some exotic Unicode combinations might need manual review\n- CSV files with inconsistent columns may need special attention\n- Excel-generated CSVs sometimes need specific dialect settings\n\n---\n\nMade with ❤️, plenty of ☕, and now with CSV power! 📊","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoacosta%2Fspanish-encoding-fixer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoacosta%2Fspanish-encoding-fixer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoacosta%2Fspanish-encoding-fixer/lists"}