Gadgets & hobbies

Electronic gadgets, hobbies, developing

Withings to Garmin tool going beyond! TrainerRoad syncing

As I’m user of cycling training platform TrainerRoad, the tool has been expanded to support weight synchronisation to TrainerRoad profile.

To use, specify Trainer Road user and passwords as shown below:

Usage

Usage: sync.py [options]

Options:
  -h, --help            show this help message and exit
  --garmin-username=<user>, --gu=<user>
                        username to login Garmin Connect.
  --garmin-password=<pass>, --gp=<pass>
                        password to login Garmin Connect.
  --trainerroad-username=<user>, --tu=<user>
                        username to login TrainerRoad.
  --trainerroad-password=<user>, --tp=<user>
                        username to login TrainerRoad.
  -f <date>, --fromdate=<date>
  -t <date>, --todate=<date>
  --no-upload           Won't upload to Garmin Connect and output binary-
                        strings to stdout.
  -v, --verbose         Run verbosely

As always – for download, best go to GitHub

Param2Clipboard

A MacOS application to grab an argument and set system Clipboard as per argument text.

How it works?

Under the hood it’s invoking pbcopy as below:

#!/bin/bash

if [[ -z "$1" ]]
then
  osascript -e 'display notification "Nothing copied!" with title "Param2Clipboard"'
else
	echo "$1" | pbcopy
	osascript -e 'display notification "Parameter copied to the Clipboard!" with title "Param2Clipboard"'
fi

The script has been wrapped into MacOS app using Platypus:

Flow

Eventually, registered required URL Types in Info.plist. Unfortunately, it was a manual process which has to be repeated every time when a new app is created using Platypus:

Flow

Why created?

Created to improve workflow when opening Microsoft Skype or Lync meetings.

Flow I’m using:

Flow

Broswer Fairy configuration

In order to capture opening of Skype/Lync URLs, I’m using Browser Fairy which is registered as a default app to open all URLs. Each URL is matched against defined list of patters and if a Skype URL is detected, the URL is passed to Param2Clipboard app.

Flow
Flow

References

Withings to Garmin Connect – resurrection

After dropping “legacy” APIs on Withings page, the script stopped to work…

It took quite a while to adjust it to OAuth2 but finally – it’s done!

Go to https://github.com/jaroslawhartman/withings-garmin-v2 to download the script.

References

  • Based on withings-garmin by Masayuki Hamasaki, improved to support SSO authorization in Garmin Connect 2.
  • SSO authorization derived from https://github.com/cpfair/tapiriik

Pre-requisites

$ sudo easy_install requests
  • simplejson
$ sudo easy_install simplejson

Usage

Usage: $python sync.py [options]

Options:
  -h, --help            show this help message and exit
  --garmin-username=<user>, --gu=<user>
                        username to login Garmin Connect.
  --garmin-password=<pass>, --gp=<pass>
                        password to login Garmin Connect.
  -f <date>, --fromdate=<date>
  -t <date>, --todate=<date>
  --no-upload           Won't upload to Garmin Connect and output binary-
                        string to stdout.
  -v, --verbose         Run verbosely

Obtaining Withings Authorization Code

When running for a very first time, you need to obtain Withings authorization:

$ ./sync.py -f 2019-01-25 -v
Can't read config file config/withings_user.json
***************************************
*         W A R N I N G               *
***************************************

User interaction needed to get Authentification Code from Withings!

Open the following URL in your web browser and copy back the token. You will have *30 seconds* before the token expires. HURRY UP!
(This is one-time activity)

https://account.withings.com/oauth2_user/authorize2?response_type=code&client_id=183e03e1f363110b3551f96765c98c10e8f1aa647a37067a1cb64bbbaf491626&state=OK&scope=user.metrics&redirect_uri=https://wieloryb.uk.to/withings/withings.html&

Token : _

You need to visit the URL listed by the script and then – copy Authentification Code back to the prompt.

This is one-time activity and it will not be needed to repeat.

Tips

You can hardcode your usernames and passwords in the script (sync.py):

GARMIN_USERNAME = ''
GARMIN_PASSWORD = ''

For advanced users – registering own Withings application

The script has been registered as a Withings application and got assigned Client ID and Consumer Secret. If you wish to create your own application – feel free!

Note, registering it is quite cumbersome, as you need to have a callback URL and an Icon. Anyway, when done, you should have the following identifiers:

IdentfierExample
Client ID183e03.................765c98c10e8f1aa647a37067a1......baf491626
Consumer Secreta75d65.................4c16719ef7bd69fa7c5d3fd0ea......ed48f1765
Callback URIhttps://jhartman.pl/withings/notify

Configure them in config/withings_app.json, for example:

{
    "callback_url": "https://wieloryb.uk.to/withings/withings.html",
    "client_id": "183e0******0b3551f96765c98c1******b64bbbaf491626",
    "consumer_secret": "a75d65******1df1514c16719ef7bd69fa7*****2e2b0ed48f1765"
}

Shrinking VirtualBox VMs

This article is note to self, as I just gather information from other sites: