forked from all-of-us/raw-data-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_organizations.sh
executable file
·72 lines (60 loc) · 1.78 KB
/
import_organizations.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash -e
# Upserts awardees, organizations, and/or sites from CSV input files in the data dir
USAGE="tools/import_organizations.sh [--account <USER>@pmi-ops.org --project <PROJECT>] [--dry_run]"
while true; do
case "$1" in
--account) ACCOUNT=$2; shift 2;;
--project) PROJECT=$2; shift 2;;
--dry_run) DRY_RUN=--dry_run; shift 1;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ -z "${ACCOUNT}" ] && [ "${PROJECT}" ];
then
echo "Usage: $USAGE"
exit 1
fi
TMP_GEOCODE_DIR=$(mktemp -d)
TMP_GEOCODE_INFO_FILE=${TMP_GEOCODE_DIR}/geocode_key.json
function cleanup {
:
}
function get_geocode_key {
echo "Getting geocode api key ..."
(tools/install_config.sh --key geocode_key --account "${ACCOUNT}" \
--project "pmi-drc-api-test" --config_output "$TMP_GEOCODE_INFO_FILE")
export API_KEY=$(cat $TMP_GEOCODE_INFO_FILE | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["'api_key'"]')
}
CREDS_ACCOUNT="${ACCOUNT}"
if [ -z "${ACCOUNT}" ]
then
echo "Using stub geocoding when --account is not specified"
GEOCODE_FLAG=--stub_geocoding
else
get_geocode_key
fi
EXTRA_ARGS="$@"
if [ "${PROJECT}" ]
then
echo "Getting credentials for ${PROJECT}..."
source tools/auth_setup.sh
run_cloud_sql_proxy
set_db_connection_string
EXTRA_ARGS+=" --creds_file ${CREDS_FILE} --instance ${INSTANCE} --project ${PROJECT}"
else
if [ -z "${DB_CONNECTION_STRING}" ]
then
source tools/setup_local_vars.sh
set_local_db_connection_string
fi
fi
source tools/set_path.sh
python tools/import_organizations.py --awardee_file data/awardees.csv \
--organization_file data/organizations.csv --site_file data/sites.csv $EXTRA_ARGS $DRY_RUN $GEOCODE_FLAG
function finish {
cleanup
rm -rf ${TMP_GEOCODE_DIR}
rm -f ${TMP_GEOCODE_INFO_FILE}
}
trap finish EXIT