Skip to content

Commit

Permalink
move to src/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
entorb committed Dec 14, 2024
1 parent fa5b263 commit 49c3950
Showing 9 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.vscode/
data/
plot/
report/

token.txt
sleep_report.txt

.DS_Store
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,15 +3,15 @@
## Setup

* `pip install -r requirements.txt`
* requires a personal access token, obtained from <https://cloud.ouraring.com/personal-access-tokens> and stored in [token.txt](token.txt)
* requires a personal access token, obtained from <https://cloud.ouraring.com/personal-access-tokens> 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))
3 changes: 0 additions & 3 deletions config.json

This file was deleted.

13 changes: 6 additions & 7 deletions 1fetch_v2.py → src/1fetch_v2.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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


4 changes: 2 additions & 2 deletions 2analyze_v2.py → src/2analyze_v2.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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",
1 change: 0 additions & 1 deletion api-v1/1fetch_v1.py → src/api-v1/1fetch_v1.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# by Dr. Torben Menke https://entorb.net
# https://github.com/entorb/analyze-oura

1 change: 0 additions & 1 deletion api-v1/2analyze_v1.py → src/api-v1/2analyze_v1.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# by Dr. Torben Menke https://entorb.net
# https://github.com/entorb/analyze-oura

1 change: 1 addition & 0 deletions src/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
date_start = "2022-01-01"

0 comments on commit 49c3950

Please sign in to comment.