|
| 1 | +# Utility Tools for create-url-list |
| 2 | + |
| 3 | +This directory contains diagnostic and conversion tools for troubleshooting CSV format issues with `create-url-list`. |
| 4 | + |
| 5 | +## Tools |
| 6 | + |
| 7 | +### debug-csv - CSV Format Inspector |
| 8 | + |
| 9 | +Inspects a CSV file to diagnose format issues and verify column names. |
| 10 | + |
| 11 | +**Build:** |
| 12 | +```bash |
| 13 | +go build -o debug-csv debug-csv.go |
| 14 | +``` |
| 15 | + |
| 16 | +**Usage:** |
| 17 | +```bash |
| 18 | +./debug-csv <csv-file-path> |
| 19 | +``` |
| 20 | + |
| 21 | +**What it shows:** |
| 22 | +- Number of columns detected |
| 23 | +- Exact column names (with quotes to reveal whitespace) |
| 24 | +- Byte representation of each column name (to detect encoding issues) |
| 25 | +- Column length |
| 26 | +- Whether required columns (`Page`, `Measure Names`, `Measure Values`) are present |
| 27 | +- Warnings about common issues: |
| 28 | + - BOM (Byte Order Mark) at start of file |
| 29 | + - Leading/trailing whitespace in column names |
| 30 | + |
| 31 | +**Example:** |
| 32 | +```bash |
| 33 | +./debug-csv ~/Downloads/analytics-data.csv |
| 34 | +``` |
| 35 | + |
| 36 | +**Sample output:** |
| 37 | +``` |
| 38 | +Found 5 columns in header: |
| 39 | +
|
| 40 | +Column 0: "Page" |
| 41 | + Bytes: [80 97 103 101] |
| 42 | + Length: 4 |
| 43 | + ✓ Matches required column 'Page' |
| 44 | +
|
| 45 | +Column 1: "Page Subsite" |
| 46 | + Bytes: [80 97 103 101 32 83 117 98 115 105 116 101] |
| 47 | + Length: 12 |
| 48 | +
|
| 49 | +Column 2: "Measure Names" |
| 50 | + Bytes: [77 101 97 115 117 114 101 32 78 97 109 101 115] |
| 51 | + Length: 13 |
| 52 | + ✓ Matches required column 'Measure Names' |
| 53 | +
|
| 54 | +Column 3: "Measure Values" |
| 55 | + Bytes: [77 101 97 115 117 114 101 32 86 97 108 117 101 115] |
| 56 | + Length: 14 |
| 57 | + ✓ Matches required column 'Measure Values' |
| 58 | +
|
| 59 | +Required columns check: |
| 60 | + ✓ 'Page' found |
| 61 | + ✓ 'Measure Names' found |
| 62 | + ✓ 'Measure Values' found |
| 63 | +
|
| 64 | +✓ All required columns present! |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +### convert-csv - CSV Format Converter |
| 70 | + |
| 71 | +Converts UTF-16 tab-delimited CSV files to UTF-8 comma-delimited format (standard CSV). |
| 72 | + |
| 73 | +**Build:** |
| 74 | +```bash |
| 75 | +go build -o convert-csv convert-csv.go |
| 76 | +``` |
| 77 | + |
| 78 | +**Usage:** |
| 79 | +```bash |
| 80 | +./convert-csv <input-file> <output-file> |
| 81 | +``` |
| 82 | + |
| 83 | +**What it does:** |
| 84 | +- Reads UTF-16 encoded files (with or without BOM) |
| 85 | +- Handles tab-delimited data |
| 86 | +- Outputs standard UTF-8 comma-delimited CSV |
| 87 | + |
| 88 | +**Example:** |
| 89 | +```bash |
| 90 | +# Convert a Tableau or Excel export |
| 91 | +./convert-csv ~/Downloads/tableau-export.csv ~/temp/converted.csv |
| 92 | + |
| 93 | +# Then use with create-url-list |
| 94 | +cd .. |
| 95 | +./create-url-list ~/temp/converted.csv 1-250 output.csv |
| 96 | +``` |
| 97 | + |
| 98 | +**Sample output:** |
| 99 | +``` |
| 100 | +Successfully converted 51396 rows from /path/to/input.csv to /path/to/output.csv |
| 101 | +Input format: UTF-16 tab-delimited |
| 102 | +Output format: UTF-8 comma-delimited |
| 103 | +``` |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Common Workflow |
| 108 | + |
| 109 | +When you encounter a "missing required columns" error: |
| 110 | + |
| 111 | +1. **Diagnose the issue:** |
| 112 | + ```bash |
| 113 | + ./debug-csv /path/to/problematic-file.csv |
| 114 | + ``` |
| 115 | + |
| 116 | +2. **If the file is UTF-16 or tab-delimited, convert it:** |
| 117 | + ```bash |
| 118 | + ./convert-csv /path/to/problematic-file.csv /path/to/fixed-file.csv |
| 119 | + ``` |
| 120 | + |
| 121 | +3. **Verify the conversion worked:** |
| 122 | + ```bash |
| 123 | + ./debug-csv /path/to/fixed-file.csv |
| 124 | + ``` |
| 125 | + |
| 126 | +4. **Use the fixed file with create-url-list:** |
| 127 | + ```bash |
| 128 | + cd .. |
| 129 | + ./create-url-list /path/to/fixed-file.csv 1-250 output.csv |
| 130 | + ``` |
| 131 | + |
| 132 | +## Dependencies |
| 133 | + |
| 134 | +The `convert-csv` tool requires the `golang.org/x/text` package: |
| 135 | + |
| 136 | +```bash |
| 137 | +go get golang.org/x/text/encoding/unicode |
| 138 | +go get golang.org/x/text/transform |
| 139 | +``` |
| 140 | + |
| 141 | +This dependency is automatically downloaded when you build the tool. |
| 142 | + |
0 commit comments