Skip to content

Commit

Permalink
Add fetch data script
Browse files Browse the repository at this point in the history
This script will make it easier for developers to spin up an
environment. It may eventually be used by build processes as well.
  • Loading branch information
Matt Stone committed Aug 26, 2022
1 parent 8315639 commit 9f8fd5b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ vendor.bundle.js
bundle.js.map
dist/
yarn-error.log
src/app/public/data

# Bundled JS
src/app/build
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ For Docker-based development, use:
./scripts/setup --docker
```

Municipal data can be downloaded with a script:

```console
./scripts/fetch-data
```

#### Development

Rebuild Docker images and run application.
Expand Down
1 change: 1 addition & 0 deletions scripts/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
if [ "${1:-}" = "--help" ]; then
usage
else
./scripts/fetch-data
./scripts/update

# Build tagged container images
Expand Down
45 changes: 45 additions & 0 deletions scripts/fetch-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e

if [[ -n "${IOW_BOUNDARY_TOOL_DEBUG}" ]]; then
set -x
fi

MUNICIPAL_BOUNDARIES_DATA_LOCATION="https://linc.osbm.nc.gov/explore/dataset/municipalities-2020/download/?format=geojson&lang=en"
MUNICIPAL_BOUNDARIES_FILENAME=muni.geo.json
DATA_DIR=src/app/public/data

function usage() {
echo -n \
"Usage: $(basename "$0")
Execute Yarn CLI commands.
"
}

function fetchData() {
if [ ! -d "$DATA_DIR" ]; then
mkdir -p "$DATA_DIR"
fi

echo "Fetching municipal data from: $MUNICIPAL_BOUNDARIES_DATA_LOCATION"
curl "${MUNICIPAL_BOUNDARIES_DATA_LOCATION}" -o "$DATA_DIR/$MUNICIPAL_BOUNDARIES_FILENAME"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [ "${1:-}" = "--help" ]; then
usage
else
if [[ -f "$DATA_DIR/$MUNICIPAL_BOUNDARIES_FILENAME" ]]; then
if [ "${1:-}" = "--force" ]; then
echo "Warning: forcing data refetching!"
rm "$DATA_DIR/$MUNICIPAL_BOUNDARIES_FILENAME"
fetchData
else
echo "Skipping data fetching: file exists."
fi
else
fetchData
fi
fi
fi
Empty file added src/app/public/data/.gitkeep
Empty file.

0 comments on commit 9f8fd5b

Please sign in to comment.