Skip to content

Commit

Permalink
API Secrets configuration moved out of python script into .cfg file
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuinigeRijder committed Aug 5, 2022
1 parent 102b1a0 commit 835ff1d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:

Expand Down
9 changes: 9 additions & 0 deletions combine_two_pvoutput_systems.cfg
Original file line number Diff line number Diff line change
@@ -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
20 changes: 13 additions & 7 deletions combine_two_pvoutput_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 835ff1d

Please sign in to comment.