Skip to content

Commit 860fd01

Browse files
authored
Merge pull request #42 from klejejs/chore/use-env-file-for-example-py
Use .env file for credentials used in example.py file
2 parents 5606e22 + a8ad0a2 commit 860fd01

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
USERNAME=
2+
PASSWORD=

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ debug.txt
1717
/.vs/*
1818

1919
.DS_Store
20+
21+
.env

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Thus, I have created a `debug()` function that runs when `example.py` is execute
1313
## How to use api:
1414
See [example.py](https://github.com/klejejs/python-thermia-online-api/blob/main/example.py) file for examples.
1515

16-
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.
16+
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.
1717

1818
## Available functions in Thermia class:
1919
| Function | Description |

credentials.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

example.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
from datetime import datetime, timedelta
22
from ThermiaOnlineAPI import Thermia
3-
from credentials import USERNAME, PASSWORD
43

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

8+
USERNAME = None
9+
PASSWORD = None
10+
11+
with open(".env", "r") as env_file:
12+
for line in env_file:
13+
if line.startswith("USERNAME="):
14+
USERNAME = line.split("=")[1].strip()
15+
elif line.startswith("PASSWORD="):
16+
PASSWORD = line.split("=")[1].strip()
17+
918
if not USERNAME or not PASSWORD:
1019
USERNAME = input("Enter username: ")
1120
PASSWORD = input("Enter password: ")

0 commit comments

Comments
 (0)