34 lines
975 B
Bash
34 lines
975 B
Bash
|
#!/bin/sh
|
||
|
set -e
|
||
|
|
||
|
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
|
||
|
|
||
|
input="$SCRIPT_DIR/data/restaurants_extended.csv"
|
||
|
output="$SCRIPT_DIR/data/restaurants_extended.jsonl"
|
||
|
|
||
|
|
||
|
# In order:
|
||
|
# - Convert CSV to JSON
|
||
|
# - Convert JSON array in JSON lines notation
|
||
|
# - Remove last line (which is all `null`)
|
||
|
cat "$input" | jq -s --raw-input --raw-output \
|
||
|
'split("\n") | .[1:-1] | map(split(",")) |
|
||
|
map({
|
||
|
"id": .[0],
|
||
|
"name": .[1],
|
||
|
"cityRaw": .[2],
|
||
|
"city": .[2] | split("/") | .[0],
|
||
|
"country": .[2] | split("/") | .[1],
|
||
|
"continent": .[2] | split("/") | .[2],
|
||
|
"location": {
|
||
|
"lon": .[8] | sub("^\"\\["; "") | sub("\\s*"; "") | tonumber,
|
||
|
"lat": .[9] | sub("\\]\"$"; "") | sub("\\s*"; "") | tonumber,
|
||
|
},
|
||
|
"averageCostForTwo": .[3],
|
||
|
"aggregateRating": .[4],
|
||
|
"ratingText": .[5],
|
||
|
"votes": .[6],
|
||
|
"date": .[7]
|
||
|
})' "$input" | \
|
||
|
jq -c '.[]' > "$output"
|