From 55550362c2f5ac6b9f23907bdcaf1cc374de6e4e Mon Sep 17 00:00:00 2001 From: Karl Cardenas Date: Tue, 9 Jul 2024 17:00:37 -0700 Subject: [PATCH] docs: updated README --- README.md | 4 ++++ cmd/dump.go | 32 +++++++++++++++++++++++++----- docs/get-started.md | 48 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 05eafc2..5ea5552 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,10 @@ The dump command downloads **all your Whoop data** and saves it to a local file. mywhoop dump ``` +| Flag | Description | Required | Default | +|---|----|---|---| +| `--location` | The location to save the Whoop data file. | No | `./data/` | + ### Login diff --git a/cmd/dump.go b/cmd/dump.go index 08fde48..a650055 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -16,8 +16,9 @@ import ( "github.com/spf13/cobra" ) -// meCmd represents the me command -var meCmd = &cobra.Command{ +var dataLocation string + +var dumpCmd = &cobra.Command{ Use: "dump", Short: "Dump all your Whoop data to a file or another form of export.", Long: "Dump all your Whoop data to a file or another form of export.", @@ -29,7 +30,8 @@ var meCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(meCmd) + dumpCmd.PersistentFlags().StringVarP(&dataLocation, "location", "l", "", "The location to dump the data to. Default is the current directory's data/ folder.") + rootCmd.AddCommand(dumpCmd) } func dump(ctx context.Context) error { @@ -161,10 +163,18 @@ func dump(ctx context.Context) error { } return err } + var filePath string switch cfg.Export.Method { case "file": - fileExp := export.NewFileExport(Configuration.Export.FileExport.FilePath, + + if dataLocation == "" { + filePath = Configuration.Export.FileExport.FilePath + } else { + filePath = dataLocation + } + + fileExp := export.NewFileExport(filePath, Configuration.Export.FileExport.FileType, Configuration.Export.FileExport.FileName, Configuration.Export.FileExport.FileNamePrefix, @@ -180,6 +190,11 @@ func dump(ctx context.Context) error { } slog.Info("Data exported successfully", "file", fileExp.FileName) case "s3": + + if dataLocation != "" { + cfg.Export.AWSS3.FileConfig.FilePath = dataLocation + } + awsS3, err := export.NewAwsS3Export(cfg.Export.AWSS3.Region, cfg.Export.AWSS3.Bucket, cfg.Export.AWSS3.Profile, @@ -200,8 +215,15 @@ func dump(ctx context.Context) error { } default: + + if dataLocation == "" { + filePath = Configuration.Export.FileExport.FilePath + } else { + filePath = dataLocation + } + slog.Info("no export method specified. Defaulting to file.") - fileExp := export.NewFileExport(Configuration.Export.FileExport.FilePath, + fileExp := export.NewFileExport(filePath, Configuration.Export.FileExport.FileType, Configuration.Export.FileExport.FileName, Configuration.Export.FileExport.FileNamePrefix, diff --git a/docs/get-started.md b/docs/get-started.md index 43320f1..7c0ec05 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -1,4 +1,4 @@ -# Get Starrted +# Get Started MyWhoop requires a few one-time setup steps to get started. The primary steps include setting up a Whoop application in the Whoop Developer Portal and setting up MyWhoop on your local machine or server. Once you have completed these steps, you can start using MyWhoop to interact with your Whoop data as you see fit. @@ -97,4 +97,48 @@ The following steps will guide you through the process of setting up MyWhoop on ![A view of the MyWhoop login page](../static/images/tutorial_4.png) -12. Click on **Close Application** and close the browser tab. \ No newline at end of file +12. Click on **Close Application** and close the browser tab. + + > [!NOTE] + > The authentication token is valid for 1 hour. If the token expires, you will need to re-authenticate with the Whoop API. You can use the `login` command to create a new token. + + +13. Issue the MyWhoop `dump` command to download all your Whoop data and save it to a local file. The `--location` flag is used to specify the location to save the Whoop data file. + + ```shell + docker run --publish 8080:8080 --volume $PWD:/app -e WHOOP_CLIENT_ID=$WHOOP_CLIENT_ID -e WHOOP_CLIENT_SECRET=$WHOOP_CLIENT_SECRET ghcr.io/karl-cardenas-coding/mywhoop:v1.0.0 dump --credentials /app/token.json --location /app + ``` + + Upon successful download, the Whoop data will be saved in the `~/mywhoop/data/` directory. The final output will look similar to the following: + + ``` + time="2024/07/09 23:51:52" level=INFO msg="data written to file" file=/app/user.json + time="2024/07/09 23:51:52" level=INFO msg="All Whoop data downloaded successfully" + ``` + +14. To review the downloaded data, navigate to the `~/mywhoop/data` directory and open the `user.json` file. The file contains all the Whoop data downloaded from the Whoop API. + + ```shell + cat ~/mywhoop/data/user.json | jq + ``` + + ```json + { + "user_data": { + "user_id": 11111111, + "email": "example@example.com", + "first_name": "John", + "last_name": "Doe " + }, + "user_mesaurements": { + "height_meter": 1.48, + "weight_kilogram": 66.678085, + "max_heart_rate": 198 + }, + ...// Additional data follows + } + ``` + + + +15. You have successfully set up MyWhoop on your local machine or server. You can now use MyWhoop to interact with your Whoop data as needed. For more information on the available commands and options, refer to the [Commands Reference](./commands_reference.md) section. \ No newline at end of file