Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ernestoongaro/9822046185deb4f2ee654b0948596152 to your computer and use it in GitHub Desktop.
Save ernestoongaro/9822046185deb4f2ee654b0948596152 to your computer and use it in GitHub Desktop.
CLIENT_ID='YOURS'
CLIENT_SECRET='YOURS'
END_POINT=https://YOURS:19999/api/3.0
LOOK_ID=12
which jq
if [ $status -gt 0 ]
then
echo "This utility requires the jq command line utility to parse JSON data. Find more information here: https://stedolan.github.io/jq/"
echo "On a mac with the brew utility installed, you should be able to install jq with the command \"brew install jq\"."
exit 255
fi
response=`curl --request POST --fail --silent --show-error "${END_POINT}/login?client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}"`
status=$?
if [ $status -gt 0 ]
then
echo "Failed logging in"
exit 1
fi
ACCESS_TOKEN=`echo $response | jq --raw-output '.access_token'`
echo "Got access token \"${ACCESS_TOKEN}\""
curl --silent -k -H "Authorization: token ${ACCESS_TOKEN}" ${END_POINT}/looks/${LOOK_ID}/run/csv?limit=250 | iconv -f utf-8 | while IFS=, read var_id l1 l2 l3 l4 l5 label status
do
echo ",max(CASE WHEN nlg_variables.variable_id = '"$var_id"' then nlg_variable_values.value_label ELSE NULL END) as "$var_id
#echo $var_id $l1 $l2 $l3 $l4 $l5 $label
done
curl --silent -k -H "Authorization: token ${ACCESS_TOKEN}" ${END_POINT}/looks/${LOOK_ID}/run/csv?limit=250 | iconv -f utf-8 | while IFS=, read var_id l1 l2 l3 l4 l5 label status
do
echo "dimension: " $var_id "{"
echo "view_label: " '"'$l1 "-" $l2'"'
echo "group_label: " '"'$l3'"'
if [ -n "$l4" ]
then
echo "description: " '"'$l4 "/" $l5'"'
fi
echo "label: " '"'$label'"'
echo "type: string"
echo "sql: \${TABLE}."$var_id ";;"
echo " }"
echo
done
echo "Logging out"
curl --request DELETE --header "Authorization: token ${ACCESS_TOKEN}" "${END_POINT}/logout"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment