-
-
Save andrewxhill/5884759 to your computer and use it in GitHub Desktop.
Import CartoDB file with cURL (Mac version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CDB_USER=$1 | |
API_KEY=$2 | |
IMPORT_FILE=$3 | |
if [[ -z $CDB_USER ]] | |
then | |
echo "Missing user" | |
fi | |
if [[ -z $API_KEY ]] | |
then | |
echo "Missing api key" | |
fi | |
if [[ -z $IMPORT_FILE ]] | |
then | |
echo "Missing file" | |
fi | |
echo "Sending file..." | |
job_id=`curl -s -F file=@${IMPORT_FILE} "https://${CDB_USER}.cartodb.com/api/v1/imports/?api_key=${API_KEY}" | sed -E 's/\{\"item_queue_id\":([0-9]+).*/\1/'` | |
echo "Waiting for job ${job_id} to be completed..." | |
while true | |
do | |
status=`curl -s "https://${CDB_USER}.cartodb.com/api/v1/imports/${job_id}?api_key=${API_KEY}" | sed -E 's/(.*)\"state\":\"([a-z]+)\"(.*)/\2/'` | |
echo "STATE: ${status}" | |
if [[ $status == 'complete' ]] | |
then | |
echo "Import successful" | |
break | |
fi | |
sleep 2 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./cdb_import.sh <cdb_username> <api_key> <filename> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment