You are a runner, cyclist or triathlete? You love Golden Cheetah? You track your activities with Garmin devices? You want to download all of them from Garmin Connect? You want to archive, cloud-backup and import automatically into Golden Cheetah? Alright, where is the problem?!? Rise a feature request and ask for new Golden Cheetah functionality! But exactly this is easier said than done:
But there are tons of alternatives and workarounds. Here is mine.
Apple claims writing a shell script is like riding a bike: „You fall off and scrape your knees a lot at first. With a bit more experience, you become comfortable riding them around…“ Awesome! For the rest I totally agree. „Shell scripting is perfect for creating small pieces of code that connect other tools together.“
Before we are diving into details some insights on my tooling: Mac user, running their latest OSX. Additional to that my preferred cloud storage is Google Drive. The latter would not make any difference to a Dropbox, Box.com or another typical cloud storage.
If it did not yet happen you need to download the following:
Follow these steps for the initial configuration.
If you decide to create these folders in your preferred cloud storage, for example a Google Drive, they get synced automatically in the background from your local client to your cloud storage.
Configuring our awesome performance software step by step.
Copy content, paste content and save as sport.sh file.
#################
# My parameters #
#################
# My Garmin Connect username
mygarminusername="USERNAME"
# My Garmin Connect password
mygarminpassword="PASSWORD"
# My number of past activities to export from Garmin Connect. Hint: Garmin API limit is 1000 max.
mynumberofexports="10"
# My GoldenCheetah backup folder
mybackupfolder=(~/GoogleDrive/Sport/GoldenCheetah/Backup/)
# My Athletelibrary folder
myathletelibraryfolder=(~/Documents/GoldenCheetah/AthleteLibrary/Johannes/)
# My Garmin Connect export script folder
mygarminconnectexportscriptfolder=(~/GoogleDrive/Sport/GoldenCheetah/GarminConnectScript/)
# My Garmin Connect exported activity folder
mygarminconnectexportsfolder=(~/GoogleDrive/Sport/GoldenCheetah/GarminConnectExports/Johannes/)
#########################################
# Export activities from Garmin Connect #
#########################################
python $mygarminconnectexportscriptfolder/gcexport.py -d $mygarminconnectexportsfolder -c "$mynumberofexports" -f original -u --username "$mygarminusername" --password "$mygarminpassword"
#####################################################
# Cleaning json as not used and required for backup #
#####################################################
cd $mygarminconnectexportsfolder
rm *.json
##############################
# Open GoldenCheetah finally #
##############################
open -a GoldenCheetah
###################
# Action required #
###################
echo Golden Cheeath opens
echo Import in background runs
echo ---------------------------------------
echo ----------- ACTION REQUIRED -----------
echo ---------------------------------------
echo Edit your downloaded activities
echo Save all edited activites
echo Create a backup?
######################
# Waiting for answer #
######################
read -p "[y] = yes. [n] = no " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
######################
# Kill GoldenCheetah #
######################
pkill GoldenCheetah
##################
# Backup Section #
##################
######################
# Grab Date und Year #
######################
todaysdate=$(date +%Y%m%d)
todaysyear=$(date +%Y)
##############
# ZIP backup #
##############
# Keep history of 5 backups
cd $mybackupfolder
ls -dt *.zip | tail -n +5 | xargs rm -rf
# Zips entire athleteslibrary folder and backups on daily basis
zip -r -9 -x ~/GoogleDrive/Sport/GoldenCheetah/AthleteLibrary/Johannes/cache/\* ~/GoogleDrive/Sport/GoldenCheetah/AthleteLibrary/Johannes/imports/\* -o $mybackupfolder/"$todaysdate".zip $myathletelibraryfolder
###############################
# Archive exported activities #
###############################
# Check and create Year Folder
mkdir $mygarminconnectexportsfolder/$todaysyear/
# move previous files to archive
mv $mygarminconnectexportsfolder/*.fit $mygarminconnectexportsfolder/$todaysyear/</pre>
The following section explains in detail what the rest of the script does. But first: You don´t have to adjust anything else there. Everything got already configured with setting the parameters.
Running the script is easy. There are various ways. Very old school with a simple terminal command: „sh sport.sh“. Or make sure that Python is installed and just double-click your *.sh.
The most important folder is your athlete directory. Everything in there gets „backuped“ and can easily get recovered with overwriting a newly created athlete:
No Guarantee
This script does NOT guarantee to get all your data or even download it correctly. Against my Garmin Connect account it works quite fine and smooth, but different Garmin Connect account settings or different data types could potentially cause problems.
Garmin Connect API
This is NOT an official feature of Garmin Connect, Garmin may very well make changes to their APIs that breaks this script (and they certainly did since this project got created for several times).
Golden Cheetah
This is NOT an official feature of Golden Cheetah, Golden Cheetah may very well make changes that breaks this script.
THIS SCRIPT IS FOR PERSONAL USE ONLY
It simulates a standard user session (i.e., in the browser), logging in using cookies and an authorization ticket. This makes the script pretty brittle. If you’re looking for a more reliable option, particularly if you wish to use this for some production service, Garmin does offer a paid API service.
Security Disclaimer
The way as the shell script is described has litte to no change of running securely. Passwords are stored plain in the script itself. It definitely has a lot of room for improvements. My intention is to keep it as simple and pragmatic for you. That is the basis to adjust it according your personal paranoia level. The most secure way would be to type it in every time you run the script.
License
MIT © 2018 Johannes Heinrich
Contributions are warmly welcome, particularly if this script stops working with Garmin Connect. You may consider opening a GitHub issue first. New features, however simple, are encouraged. Other than that, thx for using this script.