-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This satisfies most of the requirements of #1. It remains to run this on a cron job.
- Loading branch information
Showing
7 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
api/ | ||
NationalFedCodes.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#/bin/bash | ||
|
||
# Import variables | ||
source config.sh | ||
|
||
echo "Creating CSV file" | ||
|
||
# Create the headers for the CSV file. | ||
echo "GNIS_ID,FIPS_CODE" > "$CSV_FILE" | ||
|
||
# Skip the first line, pipe the 1st and 4th columns into the CSV file. | ||
sed 1d "$SOURCE_FILE" | cut -d "|" -f 1,4 >> "$CSV_FILE" | ||
|
||
# Turn every pipe symbol into a comma. | ||
sed -i -e "s/|/,/g" "$CSV_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# Get the current filename from the USGS download page. | ||
FILENAME=$(curl -s https://geonames.usgs.gov/domestic/download_data.htm |egrep -o "\/docs\/federalcodes\/NationalFedCodes_[0-9]{8}.zip") | ||
|
||
# Put together the URL for the file | ||
URL=https://geonames.usgs.gov"$FILENAME" | ||
|
||
echo Retreiving "$URL" | ||
|
||
# Get the file. | ||
curl -s "$URL" -o NationalFedCodes.zip | ||
|
||
# Extract the file's contents. | ||
unzip -p NationalFedCodes.zip > NationalFedCodes.txt | ||
|
||
# Get rid of the ZIP file. | ||
rm NationalFedCodes.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# Import variables | ||
source config.sh | ||
|
||
echo "Syncing files with S3" | ||
|
||
# Sync all recent changes | ||
cd "$OUTPUT_DIR" | ||
aws s3 sync . s3://"$BUCKET" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# The file from the U.S. Board of Geographic Names' website. | ||
SOURCE_FILE=NationalFedCodes.txt | ||
|
||
# The CSV file. | ||
CSV_FILE=united-states.csv | ||
|
||
# The local directory to store the JSON files. | ||
OUTPUT_DIR=./api | ||
|
||
# The S3 bucket where we want to host the JSON files. | ||
BUCKET=fipsgnis.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#/bin/bash | ||
echo "GNIS_ID,FIPS_CODE" > united-states.csv | ||
sed 1d NationalFedCodes.txt | cut -d "|" -f 1,4 >> united-states.csv | ||
sed -i -e "s/|/,/g" ./united-states.csv | ||
#!/bin/bash | ||
|
||
# Run each step in turn. | ||
bin/get_file.sh && bin/csv.sh && bin/api.sh && bin/upload.sh |