Skip to content

Instantly share code, notes, and snippets.

@pirate
Created September 19, 2024 08:30
Show Gist options
  • Save pirate/87cf977d1c44b700f265bcaa46a3979e to your computer and use it in GitHub Desktop.
Save pirate/87cf977d1c44b700f265bcaa46a3979e to your computer and use it in GitHub Desktop.
Download all your MapMyRide / MapMyFitness workout TCX files using your account data export CSV
#!/usr/bin/env bash
### Bash Environment Setup
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
# set -o xtrace
# set -x
# shopt -s nullglob
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
IFS=$'\n'
# File paths
INPUT_CSV="$PWD/user*_workout_history.csv"
COOKIES_FILE="$PWD/cookies.txt"
OUTPUT_DIR="$PWD/tcx_workouts"
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# Read the CSV file, skipping the header
tail -n +1 "$INPUT_CSV" | while IFS='\n' read -r line remainder; do
# Extract the workout ID and transform the URL
workout_id=$(echo "$line" | perl -pE 's#.*/workout/(\d+).*#$1#')
download_url="https://www.mapmyfitness.com/workout/export/${workout_id}/tcx"
echo "[⬇️] Downloading Workout ID: $workout_id"
echo " Original URL: $url"
echo " Download URL: $download_url"
# Download the file
wget --load-cookies="$COOKIES_FILE" "$download_url" -O "${OUTPUT_DIR}/${workout_id}.tcx"
# Check if download was successful
if [ $? -eq 0 ]; then
echo "[✅] Successfully downloaded ${workout_id}.tcx"
else
echo "[❌] Failed to download ${workout_id}.tcx"
fi
echo "-----------------------------------"
# Sleep to prevent hitting rate limit
sleep 0.65
done
echo
echo "[💾] Finished downloading $(ls -l "$OUTPUT_DIR" | wc -l) workouts."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment