Skip to content

Commit

Permalink
Merge pull request #42 from klejejs/chore/use-env-file-for-example-py
Browse files Browse the repository at this point in the history
Use .env file for credentials used in example.py file
  • Loading branch information
klejejs authored Nov 29, 2024
2 parents 5606e22 + a8ad0a2 commit 860fd01
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USERNAME=
PASSWORD=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ debug.txt
/.vs/*

.DS_Store

.env
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Thus, I have created a `debug()` function that runs when `example.py` is execute
## How to use api:
See [example.py](https://github.com/klejejs/python-thermia-online-api/blob/main/example.py) file for examples.

To execute the example file, first run `pip install -r requirements.txt` to install the required dependencies, then run `python3 example.py` to execute the example file. You will be prompted to enter your username and password, and then the example file will run. If do not want to manually enter your credentials every time, you can edit the `credentials.py` file and add your credentials there.
To execute the example file, first run `pip install -r requirements.txt` to install the required dependencies, then run `python3 example.py` to execute the example file. You will be prompted to enter your username and password, and then the example file will run. If do not want to manually enter your credentials every time, you can make a copy of `.env.example`, save it as a `.env` file, and add your credentials there.

## Available functions in Thermia class:
| Function | Description |
Expand Down
2 changes: 0 additions & 2 deletions credentials.py

This file was deleted.

11 changes: 10 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from datetime import datetime, timedelta
from ThermiaOnlineAPI import Thermia
from credentials import USERNAME, PASSWORD

CHANGE_HEAT_PUMP_DATA_DURING_TEST = (
False # Set to True if you want to change heat pump data during test
)

USERNAME = None
PASSWORD = None

with open(".env", "r") as env_file:
for line in env_file:
if line.startswith("USERNAME="):
USERNAME = line.split("=")[1].strip()
elif line.startswith("PASSWORD="):
PASSWORD = line.split("=")[1].strip()

if not USERNAME or not PASSWORD:
USERNAME = input("Enter username: ")
PASSWORD = input("Enter password: ")
Expand Down

0 comments on commit 860fd01

Please sign in to comment.