From 3a57efa9c92cc86dbe27875531b0e5628b5512be Mon Sep 17 00:00:00 2001 From: Hasdai Pacheco Date: Wed, 18 Mar 2015 10:19:36 -0600 Subject: [PATCH] Added harvest shell script --- API_TOKEN | 1 + harvest.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 API_TOKEN create mode 100644 harvest.sh diff --git a/API_TOKEN b/API_TOKEN new file mode 100644 index 0000000..478e017 --- /dev/null +++ b/API_TOKEN @@ -0,0 +1 @@ +place-your-api-token-here diff --git a/harvest.sh b/harvest.sh new file mode 100644 index 0000000..2005598 --- /dev/null +++ b/harvest.sh @@ -0,0 +1,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