From e92b06d8cc7d8062093e056d6fceaa0dd7908619 Mon Sep 17 00:00:00 2001 From: Waldo Jaquith Date: Sun, 11 Mar 2018 14:11:34 -0400 Subject: [PATCH] Add a script that will create JSON files for each record Toward #1. --- .gitignore | 1 + api.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .gitignore create mode 100755 api.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c6492c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +api/ diff --git a/api.sh b/api.sh new file mode 100755 index 0000000..2617147 --- /dev/null +++ b/api.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# The source CSV file. +SOURCE_DATA=united-states.csv + +# Where we want our JSON files to go. +OUTPUT_DIR=./api + +# Create the JSON directory. +mkdir -p "$OUTPUT_DIR" + +# Iterate through each line in the CSV file. +while read -r p; do + FIPS_VALUE=$(echo "$p" | cut -d "," -f 1) + GNIS_VALUE=$(echo "$p" | cut -d "," -f 2) + OUTPUT_FILE="$OUTPUT_DIR"/"$FIPS_VALUE".json + echo "{\"fips\":\"$FIPS_VALUE\",\"gnis\":\"$GNIS_VALUE\"}" > "$OUTPUT_FILE" +done <$SOURCE_DATA