Add script to split CSV file
This commit is contained in:
@@ -78,3 +78,52 @@ A few practical details:
|
||||
- If you do not want Mapbox to return French place names, use `--language en`.
|
||||
|
||||
The `permanent=True` setting in the script is intentional because the coordinates and Mapbox IDs are being saved into WordPress. If your Mapbox account does not support permanent geocoding, remove that setting only after confirming that your intended storage and use comply with Mapbox’s current terms.
|
||||
|
||||
|
||||
|
||||
I also needed a helper to split addresses as my initial file sometimes contrained two addresses on the same line.
|
||||
|
||||
The script will convent
|
||||
```csv
|
||||
name,address
|
||||
"Title 1 / Title 2","Address 1 / Address 2"
|
||||
"Title 3","Address 3"
|
||||
```
|
||||
|
||||
into:
|
||||
|
||||
```csv
|
||||
name,address
|
||||
Title 1,Address 1
|
||||
Title 2,Address 2
|
||||
Title 3,Address 3
|
||||
```
|
||||
|
||||
Run it like this:
|
||||
|
||||
```bash
|
||||
python split_addresses.py addresses.csv addresses-normalized.csv
|
||||
```
|
||||
|
||||
The script pairs values by position:
|
||||
|
||||
```text
|
||||
Title 1 / Title 2
|
||||
Address 1 / Address 2
|
||||
```
|
||||
|
||||
becomes:
|
||||
|
||||
```text
|
||||
Title 1 → Address 1
|
||||
Title 2 → Address 2
|
||||
```
|
||||
|
||||
It also checks that each row contains the same number of titles and addresses. For example, this input will produce an error rather than silently pairing incorrectly:
|
||||
|
||||
```csv
|
||||
name,address
|
||||
"Title 1 / Title 2","Address 1"
|
||||
```
|
||||
|
||||
This assumes `/` is always your separator. If an address can legitimately contain a slash, such as `12 A/B Main Street`, that row would need a different delimiter or special handling.
|
||||
|
||||
Reference in New Issue
Block a user