Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .env file for credentials used in example.py file #42

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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