From 5ab054f46f36a742b3c205839ac45ae5ae55e900 Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Wed, 28 Oct 2020 10:45:03 -0700 Subject: [PATCH] set to handle multiple URLs --- README.md | 11 +++++++++++ env.sample | 4 ++++ solar_edge.py | 31 ++++++++++++++++++------------- solar_edge.spec | 11 ++++++++++- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6138fc2..49b5e17 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ add to user crontab to update site every 5 minutes # Create pyinstaller ``` pyinstaller --onefile solar_edge.spec +cp dist/solar_edge ~/bin # user must have bin folder ``` add to user crontab to update site every 5 minutes @@ -56,6 +57,10 @@ URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imper INFILE=environmental_benefits_blank.png OUTFILE=solar.png FONT_FACE=Biko_Regular.otf +LINE1=81 +LINE2=157 +MARGIN=91 +COLOR=#298246 ``` # Sample .env file for scp @@ -68,5 +73,11 @@ URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imper INFILE=environmental_benefits_blank.png OUTFILE=solar.png FONT_FACE=Biko_Regular.otf +LINE1=81 +LINE2=157 +MARGIN=91 +COLOR=#298246 ``` +# Backgrounds +There are multilpe backgrounds to choose from. They can be selected by changing the ```INFILE``` variable diff --git a/env.sample b/env.sample index 7ec29ae..b5d4ba6 100644 --- a/env.sample +++ b/env.sample @@ -6,3 +6,7 @@ URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imper INFILE=environmental_benefits_blank.png OUTFILE=solar.png FONT_FACE=Biko_Regular.otf +LINE1=81 +LINE2=157 +MARGIN=91 +COLOR=#298246 diff --git a/solar_edge.py b/solar_edge.py index c93e505..5d62f7f 100755 --- a/solar_edge.py +++ b/solar_edge.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 - +import sys import urllib.request import json import os @@ -23,7 +23,6 @@ else: load_dotenv(bundle_dir + "/.env") ## get JSON from solar edge server -url = os.getenv('URL') infile = os.getenv('INFILE') outfile = os.getenv('OUTFILE') font_face = os.getenv('FONT_FACE') @@ -31,24 +30,30 @@ ssh_host = os.getenv('SSH_HOST') ssh_port = os.getenv('SSH_PORT') ssh_user = os.getenv('SSH_USER') ssh_folder = os.getenv('SSH_FOLDER') -req = urllib.request.Request(url) +line1 = int(os.getenv('LINE1')) +line2 = int(os.getenv('LINE2')) +xpos = int(os.getenv('MARGIN')) +fill_color = str(os.getenv('COLOR')) -# parsing response -r = urllib.request.urlopen(req).read() -cont = json.loads(r.decode('utf-8')) - -co2 = str(round(cont['envBenefits']['gasEmissionSaved']['co2']))+" lb" -trees = str(round(cont['envBenefits']['treesPlanted'])) +co2 = 0 +trees = 0 +url = [] +while os.getenv('URL'+str(len(url)+1)): + req = urllib.request.Request(os.getenv('URL'+str(len(url)+1))) + url.append(os.getenv('URL'+str(len(url)+1))) + # parsing response + r = urllib.request.urlopen(req).read() + cont = json.loads(r.decode('utf-8')) + co2 += round(cont['envBenefits']['gasEmissionSaved']['co2']) + trees += round(cont['envBenefits']['treesPlanted']) ## create image for website -fill_color = "#298246" -xpos = 91 image = Image.open(bundle_dir + "/" + infile) font = ImageFont.truetype(bundle_dir + "/" + font_face, 19) draw = ImageDraw.Draw(image) -draw.text((xpos, 81), co2, font=font, fill=fill_color) -draw.text((xpos, 157), trees, font=font, fill=fill_color) +draw.text((xpos, line1), str(co2)+" lb", font=font, fill=fill_color) +draw.text((xpos, line2), str(trees), font=font, fill=fill_color) image.save(outfile) diff --git a/solar_edge.spec b/solar_edge.spec index 5476e6a..4d27d90 100644 --- a/solar_edge.spec +++ b/solar_edge.spec @@ -6,7 +6,16 @@ block_cipher = None a = Analysis(['solar_edge.py'], pathex=['/home/fwarren/builds/solar_edge'], binaries=[], - datas=[('.env','.'),('Biko_Regular.otf','.'),('environmental_benefits_blank.png','.')], + datas=[ + ('.env','.'), + ('Biko_Regular.otf','.'), + ('environmental_benefits_black.png','.'), + ('environmental_benefits_blank.png','.'), + ('environmental_benefits_grey.png','.'), + ('environmental_benefits_greyb.png','.'), + ('environmental_benefits_greyw.png','.'), + ('environmental_benefits_white.png','.'), + ], hiddenimports=[], hookspath=[], runtime_hooks=[],