set to handle multiple URLs
This commit is contained in:
parent
ba56145e86
commit
5ab054f46f
11
README.md
11
README.md
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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'))
|
||||||
|
|
||||||
|
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
|
# parsing response
|
||||||
r = urllib.request.urlopen(req).read()
|
r = urllib.request.urlopen(req).read()
|
||||||
cont = json.loads(r.decode('utf-8'))
|
cont = json.loads(r.decode('utf-8'))
|
||||||
|
co2 += round(cont['envBenefits']['gasEmissionSaved']['co2'])
|
||||||
co2 = str(round(cont['envBenefits']['gasEmissionSaved']['co2']))+" lb"
|
trees += round(cont['envBenefits']['treesPlanted'])
|
||||||
trees = str(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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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=[],
|
||||||
|
Loading…
Reference in New Issue
Block a user