set to handle multiple URLs

This commit is contained in:
Fred Warren 2020-10-28 10:45:03 -07:00
parent ba56145e86
commit 5ab054f46f
4 changed files with 43 additions and 14 deletions

View File

@ -38,6 +38,7 @@ add to user crontab to update site every 5 minutes
# Create pyinstaller # Create pyinstaller
``` ```
pyinstaller --onefile solar_edge.spec 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 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 INFILE=environmental_benefits_blank.png
OUTFILE=solar.png OUTFILE=solar.png
FONT_FACE=Biko_Regular.otf FONT_FACE=Biko_Regular.otf
LINE1=81
LINE2=157
MARGIN=91
COLOR=#298246
``` ```
# Sample .env file for scp # Sample .env file for scp
@ -68,5 +73,11 @@ URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imper
INFILE=environmental_benefits_blank.png INFILE=environmental_benefits_blank.png
OUTFILE=solar.png OUTFILE=solar.png
FONT_FACE=Biko_Regular.otf 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

View File

@ -6,3 +6,7 @@ URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imper
INFILE=environmental_benefits_blank.png INFILE=environmental_benefits_blank.png
OUTFILE=solar.png OUTFILE=solar.png
FONT_FACE=Biko_Regular.otf FONT_FACE=Biko_Regular.otf
LINE1=81
LINE2=157
MARGIN=91
COLOR=#298246

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys
import urllib.request import urllib.request
import json import json
import os import os
@ -23,7 +23,6 @@ else:
load_dotenv(bundle_dir + "/.env") load_dotenv(bundle_dir + "/.env")
## get JSON from solar edge server ## get JSON from solar edge server
url = os.getenv('URL')
infile = os.getenv('INFILE') infile = os.getenv('INFILE')
outfile = os.getenv('OUTFILE') outfile = os.getenv('OUTFILE')
font_face = os.getenv('FONT_FACE') font_face = os.getenv('FONT_FACE')
@ -31,24 +30,30 @@ ssh_host = os.getenv('SSH_HOST')
ssh_port = os.getenv('SSH_PORT') ssh_port = os.getenv('SSH_PORT')
ssh_user = os.getenv('SSH_USER') ssh_user = os.getenv('SSH_USER')
ssh_folder = os.getenv('SSH_FOLDER') 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 co2 = 0
r = urllib.request.urlopen(req).read() trees = 0
cont = json.loads(r.decode('utf-8')) url = []
while os.getenv('URL'+str(len(url)+1)):
co2 = str(round(cont['envBenefits']['gasEmissionSaved']['co2']))+" lb" req = urllib.request.Request(os.getenv('URL'+str(len(url)+1)))
trees = str(round(cont['envBenefits']['treesPlanted'])) 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 ## create image for website
fill_color = "#298246"
xpos = 91
image = Image.open(bundle_dir + "/" + infile) image = Image.open(bundle_dir + "/" + infile)
font = ImageFont.truetype(bundle_dir + "/" + font_face, 19) font = ImageFont.truetype(bundle_dir + "/" + font_face, 19)
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
draw.text((xpos, 81), co2, font=font, fill=fill_color) draw.text((xpos, line1), str(co2)+" lb", font=font, fill=fill_color)
draw.text((xpos, 157), trees, font=font, fill=fill_color) draw.text((xpos, line2), str(trees), font=font, fill=fill_color)
image.save(outfile) image.save(outfile)

View File

@ -6,7 +6,16 @@ block_cipher = None
a = Analysis(['solar_edge.py'], a = Analysis(['solar_edge.py'],
pathex=['/home/fwarren/builds/solar_edge'], pathex=['/home/fwarren/builds/solar_edge'],
binaries=[], 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=[], hiddenimports=[],
hookspath=[], hookspath=[],
runtime_hooks=[], runtime_hooks=[],