Metadata-Version: 2.4
Name: csv_fix
Version: 0.3.0
Summary: A command line tool for CSV file processing
Author-email: Your Name <your.email@example.com>
License: MIT
Project-URL: Homepage, https://github.com/yourusername/csv_fix
Project-URL: Repository, https://github.com/yourusername/csv_fix
Keywords: csv,converter,cli
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: pylint>=2.0; extra == "dev"
Dynamic: license-file

# csv_fix

[![PyPI version](https://img.shields.io/pypi/v/csv_fix.svg)](https://pypi.org/project/csv_fix/)
[![Python versions](https://img.shields.io/pypi/pyversions/csv_fix.svg)](https://pypi.org/project/csv_fix/)
[![Build Status](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com)


## Instruction

This script uses state machine to fix maleformed csv file.

```txt
Usage: csv_fix.py [Options] <filename>
Options and arguments:
  [-h/--help]: Show this message.
  [-s]: Define sperator. Defaults to comma.
  [-q]: Define text qualifier. Defaults to auto detect.
  [-t]: Trim white space at the beginning and end of each field. Defaults to double quote.
  [-z]: (Being constructed) Specify timezone for time fields. Defaults to server timezone. Can also be Asia/Chongqing etc.
        For standard timezone names, refer to: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  [-k]: Skip errors and continue parsing following lines.
  <filename>: csv file name.
```

## Examples
```bash
# Input from stdin
cat test_case.csv | csv_fix
# Input from file
csv_fix -t test_case.csv
```
The processed output will be written to stdout.

## Features
### Fix Malformed CSV
Try to fix the format whenever possible. You can find test cases in `./tests/`.

The script follow this state machine to fix possible errors:

![CSV State Machine](misc/csv-states.png)

### Trim White Space

For fields that begin/end with white space can be stripped by specifying `-t`.

```bash
echo -n ' red,	yellow,green ,"red	"' | csv_fix -t
# Output: "red","yellow","green","red"
```

### Customize Seperator

Seperator can be customized. Specify seperator by `-s`.
```bash
echo -n 'A 27" monitor|"This should be good.|"|"' | csv_fix -s '|'
# Output: "A 27"" monitor"|"This should be good.|"|""
```

### Customize Qualifier
Qualifier can be customized. Specify qualifier by `-q`.
```bash
echo -n "'hello, what's up!','Not bad!'" | csv_fix -q "'"
# Output 'hello, what''s up!','Not bad!'
```
