GithubHelp home page GithubHelp logo

jaroslawhartman / withings-garmin-v2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ikasamah/withings-garmin

64.0 20.0 18.0 268 KB

Withings to Garmin Connec sync

Home Page: http://jhartman.pl/tag/fitness/

License: MIT License

Python 98.08% Dockerfile 1.46% Shell 0.46%

withings-garmin-v2's Introduction

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ Important ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

The tool has been migrated to https://github.com/jaroslawhartman/withings-sync

The old withings-garmin-v2 will not authorise anymore and cause the following error:

URL:"https://account.withings.com/oauth2_user/authorize2?response_type=code&client_id=183e03e1f363110b3551f96765c98c10e8f1aa647a37067a1cb64bbbaf491626&state=OK&scope=user.metrics&redirect_uri=https%3A%2F%2Fwieloryb.uk.to%2Fwithings%2Fwithings.html&selecteduser=2916101

Provides me with:
{"errors":[{"message":"redirect_uri_mismatch: The redirect URI provided is missing or does not match partner callback url"}]}

Get the new version from https://github.com/jaroslawhartman/withings-sync

withings-garmin-v2 (and TrainerRoad)

A tool for synchronisation of Withings (ex. Nokia Health Body) to Garmin Connect and Trainer Road.

NOTE: For Docker usage hits see at end of this document https://hub.docker.com/r/jaroslawhartman/withings-garmin

NOTE: Included support for Withings OAuth2! See 'Obtaining Withings authorization'

References

Pre-requisites

Using pip:

yum install libxml2-dev libxslt-dev gcc
pip install --upgrade pip &&     pip install requests &&     pip install lxml
$ sudo easy_install requests

  • simplejson
$ sudo easy_install simplejson

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

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

Docker

$ docker pull jaroslawhartman/withings-garmin

First start to ensure the script can start successfully:

jhartman@docker:~/withings-garmin-v2/Docker$ docker run -it --rm --name withings jaroslawhartman/withings-garmin
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

Obtaining Withings authoorisation:

$ docker run -it --name withings jaroslawhartman/withings-garmin --garmin-username=<username> --garmin-password=<password>

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 : <token>
Withings: Get Access Token
Withings: Refresh Access Token
Withings: Get Measurements
   Measurements received
JaHa.WAW.PL
Garmin Connect User Name: JaHa.WAW.PL
Fit file uploaded to Garmin Connect

And for subsequent runs:

$ docker start -i withings
Withings: Refresh Access Token
Withings: Get Measurements
   Measurements received
JaHa.WAW.PL
Garmin Connect User Name: JaHa.WAW.PL
Fit file uploaded to Garmin Connect

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

...but why would you? Better to provide them as commandline parameters.

GARMIN_USERNAME = ''
GARMIN_PASSWORD = ''

TRAINERROAD_USERNAME = ''
TRAINERROAD_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:

Identfier Example
Client ID 183e03.................765c98c10e8f1aa647a37067a1......baf491626
Consumer Secret a75d65.................4c16719ef7bd69fa7c5d3fd0ea......ed48f1765
Callback URI https://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"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.