forked from urkonn/ckanops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harvest.sh
50 lines (46 loc) · 1.15 KB
/
harvest.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
#!/bin/bash
API_TOKEN_FILE="./API_TOKEN"
CK_HOST="http://catalogo.datos.gob.mx"
NOW=$(date "+%d/%m/%Y - %H:%M:%S")
API_TOKEN="${CKAN_API_TOKEN:-null}"
PURGE=false
if [ $# -eq 0 ]; then
echo "Usage: $0 [-p] INSTITUTION_ID"
exit 2
fi
while getopts :p opt; do
case $opt in
p)
PURGE=true
;;
\?)
echo "Invalid argument: $OPTARG"
exit 2
;;
esac
done
shift $((OPTIND-1))
if [ "$API_TOKEN" == "null" ]; then
if [ -f "$API_TOKEN_FILE" ]; then
API_TOKEN=$(cat "$API_TOKEN_FILE")
else
echo "FATAL: Token file not found!"
fi
fi
if [ "$API_TOKEN" != "null" ]; then
export CKAN_HOST="$CK_HOST"
export CKAN_API_TOKEN="$API_TOKEN"
echo "$NOW ::: synchronizing $1 datasets with http://adela.datos.gob.mx/$1/catalogo.json ..."
echo "$NOW ::: synchronizing $1 datasets with http://adela.datos.gob.mx/$1/catalogo.json" >> harvest.log
#echo $CKAN_API_TOKEN
#echo $CKAN_HOST
if [ "$PURGE" = true ]; then
#echo "purge"
python ckanops.py --purge-harvest "http://adela.datos.gob.mx/$1/catalogo.json"
else
#echo "normal"
python ckanops.py --harvest "http://adela.datos.gob.mx/$1/catalogo.json"
fi
else
echo "FATAL: No API token defined"
fi