From 835ff1dd75eab454e86677ca0fefc881ef6e5fa5 Mon Sep 17 00:00:00 2001 From: Zuinige Rijder Date: Fri, 5 Aug 2022 11:19:27 +0200 Subject: [PATCH] API Secrets configuration moved out of python script into .cfg file --- README.md | 18 +++++++++--------- combine_two_pvoutput_systems.cfg | 9 +++++++++ combine_two_pvoutput_systems.py | 20 +++++++++++++------- 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 combine_two_pvoutput_systems.cfg diff --git a/README.md b/README.md index 6bbeb5b..0bf6482 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,13 @@ The python script requires multiple PVOutput API_KEY and SYSTEM_ID to function. * Save your settings ## Configuration -Change in combine_two_pvoutput_systems.py the following lines with your above obtained secrets: -* PVOUTPUT_SOURCE1_API_KEY = 'xxxx' -* PVOUTPUT_SOURCE1_SYSTEM_ID = 'xxxx' -* PVOUTPUT_SOURCE2_API_KEY = 'xxxx' -* PVOUTPUT_SOURCE2_SYSTEM_ID = 'xxxx' -* PVOUTPUT_TARGET_API_KEY = 'xxxx' -* PVOUTPUT_TARGET_SYSTEM_ID = 'xxxx' +Change in combine_two_pvoutput_systems.cfg the following lines with your above obtained secrets: +* pvoutput_source1_api_key = a930b6cfe4c326b0b15b83bc3501ddf123456789 +* pvoutput_source1_system_id = 12345 +* pvoutput_source2_api_key = 0f2dd8190d00369ec893b059034dde1123456789 +* pvoutput_source2_system_id = 12346 +* pvoutput_target_api_key = 6d7be6f183fc02c53f5792d1ec37180123456789 +* pvoutput_target_system_id = 12347 ## Usage ### Windows 10 @@ -43,8 +43,8 @@ combine_two_pvoutput_systems.py script runs on my Raspberry pi Model B with 512 ### Raspberry pi Configuration Steps: * create a directory solis in your home directory -* copy pvoutput.sh and combine_two_pvoutput_systems.py in this solis directory -* change inside combine_two_pvoutput_systems.py the API_KEY and SYSTEM_ID secrets +* copy pvoutput.sh, combine_two_pvoutput_systems.py and combine_two_pvoutput_systems.cfg in this solis directory +* change inside combine_two_pvoutput_systems.cfg the API_KEY and SYSTEM_ID secrets * chmod + x pvoutput.sh * add the following line in your crontab -e: diff --git a/combine_two_pvoutput_systems.cfg b/combine_two_pvoutput_systems.cfg new file mode 100644 index 0000000..53b3a00 --- /dev/null +++ b/combine_two_pvoutput_systems.cfg @@ -0,0 +1,9 @@ +[api_secrets] +pvoutput_source1_api_key = a930b6cfe4c326b0b15b83bc3501ddf123456789 +pvoutput_source1_system_id = 12345 + +pvoutput_source2_api_key = 0f2dd8190d00369ec893b059034dde1123456789 +pvoutput_source2_system_id = 12346 + +pvoutput_target_api_key = 6d7be6f183fc02c53f5792d1ec37180123456789 +pvoutput_target_system_id = 12347 \ No newline at end of file diff --git a/combine_two_pvoutput_systems.py b/combine_two_pvoutput_systems.py index b88b764..f53086c 100644 --- a/combine_two_pvoutput_systems.py +++ b/combine_two_pvoutput_systems.py @@ -5,19 +5,25 @@ """ import time import sys +import configparser from datetime import datetime from urllib.error import HTTPError, URLError from urllib.request import urlopen, Request -# == Secrets, fill in yours ================================================== -PVOUTPUT_SOURCE1_API_KEY = 'xxxx' -PVOUTPUT_SOURCE1_SYSTEM_ID = 'xxxx' +# == read api_secrets in combine_two_pvoutput_systems.cfg ==================== +parser = configparser.ConfigParser() +parser.read('combine_two_pvoutput_systems.cfg') +api_secrets = dict(parser.items('api_secrets')) -PVOUTPUT_SOURCE2_API_KEY = 'xxxx' -PVOUTPUT_SOURCE2_SYSTEM_ID = 'xxxx' +# == Secrets, fill in yours in combine_two_pvoutput_systems.cfg ============== +PVOUTPUT_SOURCE1_API_KEY = api_secrets['pvoutput_source1_api_key'] +PVOUTPUT_SOURCE1_SYSTEM_ID = api_secrets['pvoutput_source1_system_id'] -PVOUTPUT_TARGET_API_KEY = 'xxxx' -PVOUTPUT_TARGET_SYSTEM_ID = 'xxxx' +PVOUTPUT_SOURCE2_API_KEY = api_secrets['pvoutput_source2_api_key'] +PVOUTPUT_SOURCE2_SYSTEM_ID = api_secrets['pvoutput_source2_system_id'] + +PVOUTPUT_TARGET_API_KEY = api_secrets['pvoutput_target_api_key'] +PVOUTPUT_TARGET_SYSTEM_ID = api_secrets['pvoutput_target_system_id'] # == Constants =============================================================== PVOUTPUT_GET_URL = 'https://pvoutput.org/service/r2/getstatus.jsp'