From 49c3950e1866c31264b62a3ec7cfb57db734b128 Mon Sep 17 00:00:00 2001 From: Torben <59419684+entorb@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:25:11 +0100 Subject: [PATCH] move to src/ dir --- .gitignore | 2 +- .pre-commit-config.yaml | 8 ++++---- README.md | 12 ++++++------ config.json | 3 --- 1fetch_v2.py => src/1fetch_v2.py | 13 ++++++------- 2analyze_v2.py => src/2analyze_v2.py | 4 ++-- {api-v1 => src/api-v1}/1fetch_v1.py | 1 - {api-v1 => src/api-v1}/2analyze_v1.py | 1 - src/config.toml | 1 + 9 files changed, 20 insertions(+), 25 deletions(-) delete mode 100644 config.json rename 1fetch_v2.py => src/1fetch_v2.py (88%) mode change 100755 => 100644 rename 2analyze_v2.py => src/2analyze_v2.py (98%) mode change 100755 => 100644 rename {api-v1 => src/api-v1}/1fetch_v1.py (98%) mode change 100755 => 100644 rename {api-v1 => src/api-v1}/2analyze_v1.py (99%) mode change 100755 => 100644 create mode 100644 src/config.toml diff --git a/.gitignore b/.gitignore index 13c6bd4..2321ded 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ .vscode/ data/ plot/ +report/ token.txt -sleep_report.txt .DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 02fbca5..723439e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ exclude: | repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-added-large-files args: ["--maxkb=500"] @@ -62,7 +62,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.6.1" + rev: "v0.8.3" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -90,14 +90,14 @@ repos: # - id: mypy - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.41.0 + rev: v0.43.0 hooks: - id: markdownlint args: ["--disable", "MD013"] # code spell check via cspell - repo: https://github.com/streetsidesoftware/cspell-cli - rev: v8.13.3 + rev: v8.16.1 hooks: - id: cspell diff --git a/README.md b/README.md index db9d4c2..5f21908 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,15 @@ ## Setup * `pip install -r requirements.txt` -* requires a personal access token, obtained from and stored in [token.txt](token.txt) +* requires a personal access token, obtained from and stored as [token.txt](token.txt) -## Running +## Run -* set the start date in [config.json](config.json) -* [1fetch_v2.py](1fetch_v2.py): download your Oura data -* [2analyze_v2.py](2analyze_v2.py): analyze your Oura data +* set the start date in [config.toml](src/config.toml) +* [1fetch_v2.py](src/1fetch_v2.py): download your Oura data to [data/](data/) +* [2analyze_v2.py](src/2analyze_v2.py): analyze your Oura data ## Results * correlation of SleepStart and SleepDuration on various parameters -* output as chart and text files +* output as chart (dir [plot/](plot/)) and text file ([sleep_report.txt](report/sleep_report.txt)) diff --git a/config.json b/config.json deleted file mode 100644 index 0e42e9b..0000000 --- a/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "date_start": "2021-12-30" -} diff --git a/1fetch_v2.py b/src/1fetch_v2.py old mode 100755 new mode 100644 similarity index 88% rename from 1fetch_v2.py rename to src/1fetch_v2.py index 8dc3509..4722027 --- a/1fetch_v2.py +++ b/src/1fetch_v2.py @@ -1,31 +1,30 @@ -#!/usr/bin/env python3 # by Dr. Torben Menke https://entorb.net # https://github.com/entorb/analyze-oura """ Fetch Oura day-summary data from Oura Cloud API. -requires a personal access token from https://cloud.ouraring.com/personal-access-tokens provide your personal access token in file token.txt -set the start date in config.json +set the start date in config.toml fetched data is stored in data/ """ -# standard modules import json +import tomllib from pathlib import Path import requests Path("data").mkdir(exist_ok=True) -with Path("config.json").open(encoding="utf-8") as fh: - config = json.load(fh) +with (Path("src/config.toml")).open("rb") as f: + config = tomllib.load(f) + print(config) try: with Path("token.txt").open() as fh: token = fh.read().strip() # trim spaces except FileNotFoundError: - msg = "token.txt not found." + msg = "token.txt not found, see README.md for instructions." raise FileNotFoundError(msg) from None diff --git a/2analyze_v2.py b/src/2analyze_v2.py old mode 100755 new mode 100644 similarity index 98% rename from 2analyze_v2.py rename to src/2analyze_v2.py index c63954f..a1f161e --- a/2analyze_v2.py +++ b/src/2analyze_v2.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # by Dr. Torben Menke https://entorb.net # https://github.com/entorb/analyze-oura """ @@ -21,9 +20,10 @@ # import matplotlib.ticker as mtick Path("plot").mkdir(exist_ok=True) +Path("report").mkdir(exist_ok=True) # empty file -fh_report = Path("sleep_report.txt").open( # noqa: SIM115 +fh_report = Path("report/sleep_report.txt").open( # noqa: SIM115 mode="w", encoding="utf-8", newline="\n", diff --git a/api-v1/1fetch_v1.py b/src/api-v1/1fetch_v1.py old mode 100755 new mode 100644 similarity index 98% rename from api-v1/1fetch_v1.py rename to src/api-v1/1fetch_v1.py index ad4cfc3..b8fac87 --- a/api-v1/1fetch_v1.py +++ b/src/api-v1/1fetch_v1.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # by Dr. Torben Menke https://entorb.net # https://github.com/entorb/analyze-oura diff --git a/api-v1/2analyze_v1.py b/src/api-v1/2analyze_v1.py old mode 100755 new mode 100644 similarity index 99% rename from api-v1/2analyze_v1.py rename to src/api-v1/2analyze_v1.py index c8372c2..4c56841 --- a/api-v1/2analyze_v1.py +++ b/src/api-v1/2analyze_v1.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # by Dr. Torben Menke https://entorb.net # https://github.com/entorb/analyze-oura diff --git a/src/config.toml b/src/config.toml new file mode 100644 index 0000000..39a8b1c --- /dev/null +++ b/src/config.toml @@ -0,0 +1 @@ +date_start = "2022-01-01"