-
Notifications
You must be signed in to change notification settings - Fork 0
/
cclw-ingest.sh
executable file
·55 lines (48 loc) · 1.5 KB
/
cclw-ingest.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
#!/bin/bash
# This script is designed to be source'ed into your current shell
#
export CSV_FILE="/home/peter/Documents/csv/cclw-2023-10-09-docs.csv"
export CSV_EVENTS="/home/peter/Documents/csv/cclw-2023-10-09-events.csv"
#export API_HOST="http://localhost:8888"
export API_HOST="https://app.dev.climatepolicyradar.org"
# ---------- Functions ----------
get_token() {
curl -s \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=$SUPERUSER_EMAIL&password=$SUPERUSER_PASSWORD" \
${API_HOST}/api/tokens | \
jq ".access_token" | tr -d '"'
}
validate_csv() {
TOKEN=$(get_token)
URL=${API_HOST}/api/v1/admin/bulk-ingest/validate/cclw
echo Validating from ${URL}
curl -v \
-H "Authorization: Bearer ${TOKEN}" \
-F "law_policy_csv=@${CSV_FILE}" \
-F "events_csv=@${CSV_EVENTS}" \
${URL}
}
upload_csv() {
TOKEN=$(get_token)
URL=${API_HOST}/api/v1/admin/bulk-ingest/cclw
echo Uploading to ${URL}
curl -v \
-H "Authorization: Bearer ${TOKEN}" \
-F "law_policy_csv=@${CSV_FILE}" \
-F "events_csv=@${CSV_EVENTS}" \
${URL}
}
if [ -z $SUPERUSER_PASSWORD $SUPERUSER_EMAIL ] ;
then
echo env not right
else
echo The following functions are now available:
echo " 👉 validate_csv"
echo " 👉 upload_csv"
echo ""
echo "These use teh env vars: "
echo " 👉 API_HOST: $API_HOST"
echo " 👉 CSV_FILE: $CSV_FILE"
echo " 👉 CSV_EVENTS: $CSV_EVENTS"
fi