diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..77faf11 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +USERNAME= +PASSWORD= diff --git a/.gitignore b/.gitignore index 4adc92b..e3a124a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ debug.txt /.vs/* .DS_Store + +.env diff --git a/README.md b/README.md index b05f1a8..f21eff9 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/credentials.py b/credentials.py deleted file mode 100644 index 92b1dfa..0000000 --- a/credentials.py +++ /dev/null @@ -1,2 +0,0 @@ -USERNAME = "" -PASSWORD = "" diff --git a/example.py b/example.py index ad78e21..2605dd8 100644 --- a/example.py +++ b/example.py @@ -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: ")