-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple users #84
base: master
Are you sure you want to change the base?
Changes from all commits
eb3838c
bc32074
ea25656
71da33a
3222bf5
c1f3fcc
12a0d44
b29e682
939917f
2186488
e3ec588
a311625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,68 +16,32 @@ A tool for synchronisation of the Withings API to: | |
* Based on [withings-garmin](https://github.com/ikasamah/withings-garmin) by Masayuki Hamasaki, improved to support SSO authorization in Garmin Connect 2. | ||
* Based on [withings-garmin-v2](https://github.com/jaroslawhartman/withings-garmin-v2) by Jarek Hartman, improved Python 3 compatability, code-style and setuptools packaging, Kubernetes and Docker support. | ||
|
||
## Installation | ||
|
||
```bash | ||
$ pip install withings-sync | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
usage: withings-sync [-h] [--garmin-username GARMIN_USERNAME] [--garmin-password GARMIN_PASSWORD] [--trainerroad-username TRAINERROAD_USERNAME] [--trainerroad-password TRAINERROAD_PASSWORD] [--fromdate DATE] | ||
[--todate DATE] [--to-fit] [--to-json] [--output BASENAME] [--no-upload] [--verbose] | ||
usage: withings-sync [-h] [--withings-userid WITHINGS_USERID] [--garmin-upload] [--trainerroad-upload] [--fromdate DATE] | ||
[--todate DATE] [--to-fit] [--to-json] [--output BASENAME] [--verbose] | ||
|
||
A tool for synchronisation of Withings (ex. Nokia Health Body) to Garmin Connect and Trainer Road or to provide a json string. | ||
|
||
optional arguments: | ||
-h, --help show this help message and exit | ||
--garmin-username GARMIN_USERNAME, --gu GARMIN_USERNAME | ||
username to log in to Garmin Connect. | ||
--garmin-password GARMIN_PASSWORD, --gp GARMIN_PASSWORD | ||
password to log in to Garmin Connect. | ||
--trainerroad-username TRAINERROAD_USERNAME, --tu TRAINERROAD_USERNAME | ||
username to log in to TrainerRoad. | ||
--trainerroad-password TRAINERROAD_PASSWORD, --tp TRAINERROAD_PASSWORD | ||
password to log in to TrainerRoad. | ||
--withings-userid WITHINGS_USERID, --wuid WITHINGS_USERID | ||
API userid to use for Withings. | ||
--garmin-upload, --gu | ||
upload to Garmin Connect. | ||
--trainerroad-upload, --tu | ||
upload to TrainerRoad. | ||
--fromdate DATE, -f DATE | ||
--todate DATE, -t DATE | ||
--to-fit, -F Write output file in FIT format. | ||
--to-json, -J Write output file in JSON format. | ||
--output BASENAME, -o BASENAME | ||
Write downloaded measurements to file. | ||
--no-upload Won't upload to Garmin Connect or TrainerRoad. | ||
--verbose, -v Run verbosely | ||
``` | ||
|
||
### Providing credentials via environment variables | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great if you could describe, that username and password are requested during first run. |
||
|
||
You can use the following environment variables for providing the Garmin and/or Trainerroad credentials: | ||
|
||
- `GARMIN_USERNAME` | ||
- `GARMIN_PASSWORD` | ||
- `TRAINERROAD_USERNAME` | ||
- `TRAINERROAD_PASSWORD` | ||
|
||
### Providing credentials via secrets files | ||
|
||
You can also populate the following 'secrets' files to provide the Garmin and/or Trainerroad credentials: | ||
|
||
- `/run/secrets/garmin_username` | ||
- `/run/secrets/garmin_password` | ||
- `/run/secrets/trainerroad_username` | ||
- `/run/secrets/trainerroad_password` | ||
|
||
Secrets are useful in an orchestrated container context — see the [Docker Swarm](https://docs.docker.com/engine/swarm/secrets/) or [Rancher](https://rancher.com/docs/rancher/v1.6/en/cattle/secrets/) docs for more information on how to securely inject secrets into a container. | ||
|
||
### Order of priority for credentials | ||
|
||
In the case of credentials being available via multiple means (e.g. [environment variables](#providing-credentials-via-environment-variables) and [secrets files](#providing-credentials-via-secrets-files)), the order of resolution for determining which credentials to use is as follows, with later methods overriding credentials supplied by an earlier method: | ||
|
||
1. Read secrets file(s) | ||
2. Read environment variable(s) | ||
3. Use command invocation arugment(s) | ||
|
||
### Obtaining Withings Authorization Code | ||
|
||
When running for a very first time, you need to obtain Withings authorization: | ||
|
@@ -123,82 +87,3 @@ E.g. by running the script every 10 minutes. | |
|
||
See also: https://github.com/jaroslawhartman/withings-sync/issues/31 | ||
|
||
### Docker | ||
|
||
``` | ||
$ docker pull ghcr.io/jaroslawhartman/withings-sync:master | ||
``` | ||
|
||
First start to ensure the script can start successfully: | ||
|
||
|
||
Obtaining Withings authorisation: | ||
|
||
``` | ||
$ docker run -v $HOME:/root --interactive --tty --name withings ghcr.io/jaroslawhartman/withings-sync:master --garmin-username=<username> --garmin-password=<password> | ||
|
||
Can't read config file config/withings_user.json | ||
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 | ||
``` | ||
|
||
### Run a periodic Kubernetes job | ||
|
||
Edit the credentials in `contrib/k8s-job.yaml` and run: | ||
|
||
```bash | ||
$ kubectl apply -f contrib/k8s-job.yaml | ||
``` | ||
|
||
### 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! | ||
|
||
|
||
* First you need a Withings account. [Sign up here](https://account.withings.com/connectionuser/account_create). | ||
* Then you need a a Withings developer app registered. [Create your app here](https://account.withings.com/partner/add_oauth2). | ||
|
||
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" | ||
} | ||
``` | ||
|
||
For the callback URL you will need to setup a webserver hosting `contrib/withings.html`. |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, from the describtion its not quite clear:
Is this a withings specific user id or is it just a valu i want for this user? Should I geht this from the api or can I just use 42?