mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-05 18:42:55 +00:00
enable authentication of TracTrac requests also from command-line
This commit is contained in:
1 parent
9a245fd9c3
commit
d6e4e53ea6
3 files changed
+22
-8
No files matched your search
+7
-2
@@ -3,6 +3,8 @@
|
||||
# Downloads all TracTrac event data based on ${GIT_ROOT}/configuration/tractrac-json-urls
|
||||
# into the target directory (specified as $1) for those event URLs whose specific folder
|
||||
# does not yet exist in the target directory.
|
||||
# The TRACTRAC_API_TOKEN environment variable must contain a TracTrac API token valid for
|
||||
# reading the events. It will be passed on to the downloadTracTracEvent script
|
||||
TARGET_DIR="${1}"
|
||||
if [[ $# -eq 1 ]]; then
|
||||
GIT_ROOT=/home/wiki/gitwiki
|
||||
@@ -14,10 +16,13 @@ for i in `cat "${JSON_URLS_FILE}"`; do
|
||||
EVENT_DB="$( basename $( dirname ${i} ) )"
|
||||
if [ -d "${TARGET_DIR}/${EVENT_DB}" ]; then
|
||||
echo "Directory for event ${EVENT_DB} already found. Not downloading again. Use"
|
||||
echo " downloadTracTracEvent ${i} ${TARGET_DIR}"
|
||||
echo " ${GIT_ROOT}/configuration/downloadTracTracEvent ${i} ${TARGET_DIR}"
|
||||
echo "to force an update."
|
||||
else
|
||||
echo "Did not find directory for event ${EVENT_DB} yet in ${TARGET_DIR}. Downloading..."
|
||||
downloadTracTracEvent "${i}" "${TARGET_DIR}"
|
||||
if [ -n "${TRACTRAC_API_TOKEN}" ]; then
|
||||
echo "Using authenticated requests for the params files"
|
||||
fi
|
||||
downloadTracTracEvent "${i}" "${TARGET_DIR}" "${TRACTRAC_API_TOKEN}"
|
||||
fi
|
||||
done
|
||||
+14
-5
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Example usage:
|
||||
# ./downloadTracTracEvent https://event.tractrac.com/events/event_20150625_KielerWoch/jsonservice.php /tmp/KielerWoche2015
|
||||
# ./downloadTracTracEvent https://event.tractrac.com/events/event_20150625_KielerWoch/jsonservice.php /tmp/KielerWoche2015 [ {TracTracAPIToken} ]
|
||||
#
|
||||
# To obtain the set of TracTrac JSON URLs currently in use by the archive, on
|
||||
# dbserver.internal.sapsailing.com try this:
|
||||
@@ -9,25 +9,34 @@
|
||||
# for i in `cat /tmp/tractrac-json-urls`; do ./downloadTracTracEvent $i /tmp/tractrac-tracks; done
|
||||
# and you will get a folder per event under /tmp/tractrac-tracks with all .mtb and .txt files as well
|
||||
# as the .json file in them.
|
||||
# If a TracTrac API token is passed as the last parameter, it will be used to authenticate the requests
|
||||
# made to TracTrac.
|
||||
EVENT_JSON_URL="${1}"
|
||||
EVENT_DB="$( basename $( dirname ${EVENT_JSON_URL} ) )"
|
||||
TARGET_DIR="${2}/${EVENT_DB}"
|
||||
TRACTRAC_API_TOKEN="${3}"
|
||||
if [ -n "${TRACTRAC_API_TOKEN}" ]; then
|
||||
WGET_AUTHENTICATION_OPTION="--header=Authorization: Bearer ${TRACTRAC_API_TOKEN}"
|
||||
echo "Authenticating the TracTrac requests"
|
||||
else
|
||||
WGET_AUTHENTICATION_OPTION=""
|
||||
fi
|
||||
if [ ! -d "${TARGET_DIR}" ]; then
|
||||
echo "${TARGET_DIR} does not exist; making it..."
|
||||
mkdir -p "${TARGET_DIR}"
|
||||
fi
|
||||
pushd "${TARGET_DIR}"
|
||||
# create a patched version of the .json file that uses only relative params_url values:
|
||||
wget -O - "${EVENT_JSON_URL}" | sed -e 's/"params_url":"[^"]*\/\([^"/]*\.txt\)"/"params_url":"\1"/g' >"${EVENT_DB}.json"
|
||||
for params_url in `wget -O - "${EVENT_JSON_URL}" | jq -r '.races[].params_url'`; do
|
||||
wget -O - "${WGET_AUTHENTICATION_OPTION}" "${EVENT_JSON_URL}" | sed -e 's/"params_url":"[^"]*\/\([^"/]*\.txt\)"/"params_url":"\1"/g' >"${EVENT_DB}.json"
|
||||
for params_url in `wget -O - "${WGET_AUTHENTICATION_OPTION}" "${EVENT_JSON_URL}" | jq -r '.races[].params_url'`; do
|
||||
echo ${params_url}
|
||||
wget "${params_url}"
|
||||
wget "${WGET_AUTHENTICATION_OPTION}" "${params_url}"
|
||||
FILE="`basename ${params_url}`"
|
||||
STORED_URI_PART=`grep -i ^stored-uri: "${FILE}" | head -1 | sed -e 's/^stored-uri://'`
|
||||
STORED_URI="`dirname ${EVENT_JSON_URL}`/${STORED_URI_PART}"
|
||||
echo "stored-uri: ${STORED_URI}"
|
||||
# presumably the dirname of the stored URI is something like "datafiles"
|
||||
mkdir -p `dirname ${STORED_URI_PART}`
|
||||
wget -O "${STORED_URI_PART}" "${STORED_URI}"
|
||||
wget -O "${STORED_URI_PART}" "${WGET_AUTHENTICATION_OPTION}" "${STORED_URI}"
|
||||
done
|
||||
popd
|
||||
+1
-1
@@ -1 +1 @@
|
||||
15 12 * * * export PATH=/bin:/usr/bin:/usr/local/bin; downloadNewArchivedTracTracEvents.sh /home/trac/static/TracTracTracks "/home/wiki/gitwiki" >/home/wiki/downloadNewArchivedTracTracEvents.out 2>/home/wiki/downloadNewArchivedTracTracEvents.err
|
||||
15 12 * * * export PATH=/bin:/usr/bin:/usr/local/bin; . /home/wiki/secrets; export TRACTRAC_API_TOKEN; downloadNewArchivedTracTracEvents.sh /home/trac/static/TracTracTracks "/home/wiki/gitwiki" >/home/wiki/downloadNewArchivedTracTracEvents.out 2>/home/wiki/downloadNewArchivedTracTracEvents.err
|
||||
Reference in new issue
Block a user