-
-
Save dgvalde/4bb9a9dc2162c27440a978b217c01b7e to your computer and use it in GitHub Desktop.
#!/bin/bash | |
#Credits | |
#margusl (https://gist.github.com/marguslt) | |
#David (https://gist.github.com/dgvalde) | |
source mc_env.sh | |
echo "App key: $APPKEY" | |
echo "User key: $USERKEY" | |
echo "User mail: $MCMAIL" | |
echo "Agent: $MCUAGENT" | |
echo "******************************" | |
echo "" | |
if [ "$#" -ne 1 ]; then | |
echo "Error: Illegal number of parameters. Please provide the Id for the workout you wish to download" | |
else | |
echo "Download json workout for given ID" | |
http get https://uiservices.movescount.com/rules/$1 type==guidance appkey=="$APPKEY" userkey=="$USERKEY" email=="$MCMAIL" User-Agent:"$MCUAGENT" | jq "del(.Binary)" | jq -rc .Source | base64 -d | jq -r . > download_workout.json | |
echo "download_workout.json has been created" | |
fi |
#!/bin/bash | |
#Credits | |
#margusl (https://gist.github.com/marguslt) | |
#David (https://gist.github.com/dgvalde) | |
source mc_env.sh | |
echo "App key: $APPKEY" | |
echo "User key: $USERKEY" | |
echo "User mail: $MCMAIL" | |
echo "Agent: $MCUAGENT" | |
echo "******************************" | |
echo "" | |
echo "Listing all workouts on Ambit" | |
http get https://uiservices.movescount.com/rules/private type==guidance appkey=="$APPKEY" userkey=="$USERKEY" email=="$MCMAIL" User-Agent:"$MCUAGENT" | jq ".[] | del(.Binary, .Source)" | |
#!/bin/bash | |
#Credits | |
#margusl (https://gist.github.com/marguslt) | |
#David (https://gist.github.com/dgvalde) | |
source mc_env.sh | |
echo "App key: $APPKEY" | |
echo "User key: $USERKEY" | |
echo "User mail: $MCMAIL" | |
echo "Agent: $MCUAGENT" | |
echo "******************************" | |
echo "" | |
echo "Listing all workouts on Ambit" | |
http get https://uiservices.movescount.com/userdevices/$AMBIT_SN/rules type==guidance appkey=="$APPKEY" userkey=="$USERKEY" email=="$MCMAIL" User-Agent:"$MCUAGENT" | jq ".[] | del(.Binary, .Source)" |
#Credits | |
#margusl (https://gist.github.com/marguslt) | |
#Watch Serial number: | |
#AMBIT_SN (for Moveslink2: %AppData%\Roaming\Suunto\Moveslink2\Settings.xml as Device ID) | |
AMBIT_SN=... | |
#AppKey (for Moveslink2 needed for Ambit3) | |
APPKEY=HpF9f1qV5qrDJ1hY1QK1diThyPsX10Mh4JvCw9xVQSglJNLdcwr3540zFyLzIC3e | |
#UserKey (for Suuntolink: %AppData%\Suuntolink\suuntolink_data.json ) | |
#UserKey (for Moveslink2: %AppData%\Roaming\Suunto\Moveslink2\Settings.xml) | |
USERKEY=... | |
#Mail used with MC account | |
MCMAIL=.. | |
#User-Agent used for MC queries: | |
MCUAGENT="Komposti/2.29.0 (Android=5.1.1) ArREST/1.0 libcurl/7.47.0" |
{ | |
"ActivityID": 1, | |
"Category": "guidance", | |
"IsPublic": false, | |
"Name": "RULE_NAME", | |
"OutputFormat": "onedecimal", | |
"Source": "RULE_SRC", | |
"Type": "guidance" | |
} |
#!/bin/bash | |
#Credits | |
#margusl (https://gist.github.com/marguslt) | |
#David (https://gist.github.com/dgvalde) | |
source mc_env.sh | |
echo "App key: $APPKEY" | |
echo "User key: $USERKEY" | |
echo "User mail: $MCMAIL" | |
echo "Agent: $MCUAGENT" | |
echo "******************************" | |
echo "" | |
if [ "$#" -ne 1 ]; then | |
echo "Error: Illegal number of parameters. Please add name of the workout file you wish to uplaod without the .json extension" | |
else | |
if test -f "rule_template.json"; then | |
if test -f "$1.json"; then | |
echo "$1.json exists." | |
echo "Encoding workout file" | |
jq -rc . "$1.json" | base64 -w0 > "$1.base64" | |
echo "" | |
echo "Creating rule file" | |
sed -e "s/RULE_NAME/$1/g" -e "s/RULE_SRC/$(<"$1.base64")/g" < rule_template.json > "$1-rule.json" | |
echo "Posting the new workout" | |
jq -cr . "$1-rule.json" | http post https://uiservices.movescount.com/rules/ appkey=="$APPKEY" userkey=="$USERKEY" email=="$MCMAIL" User-Agent:"$MCUAGENT" | |
else | |
echo "Error: $1.json does not exists." | |
fi | |
else | |
echo "Error: rule_template.json does not exists." | |
fi | |
fi |
Also errors in file download_workout.sh
in line 21: missed argument (handcoded) and invalid option d
for base64
.
Fixed as:
http get https://uiservices.movescount.com/rules/$1 type==guidance appkey=="$APPKEY" userkey=="$USERKEY" email=="$MCMAIL" User-Agent:"$MCUAGENT" | jq "del(.Binary)" | jq -rc .Source | base64 -D | jq -r . > download_workout.json
@myadzel Those were copy-paste errors :-(. Many thanks Alexander for the catch!
@myadzel: On my systems (both Ubuntu 20.04 and Windows with Cygwin) base64 does not recognize "-D" as a valid option and needs to be "-d". Also see the man page for Base64 on GNU Utils.
Maybe you are using a different implementation of Base64 not provided by GNU utils?
I am reverting that back on this gist
https://superuser.com/a/769829
We have a platform specific problem with parameter names. I think it's worth making a platform independent version of this code.
In the file
list_ambit_workouts.sh
, the variables from the config (mc_env.sh
) are overwritten (you need to delete lines from 9 to 21).