Inital Commit
This commit is contained in:
commit
651a4db540
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.direnv/*
|
||||||
|
__pycache__/*
|
||||||
|
.env
|
BIN
Biko_Regular.otf
Normal file
BIN
Biko_Regular.otf
Normal file
Binary file not shown.
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Solar Edge Status Updater
|
||||||
|
When placed in a cron job this uppdater will make an https call to a json api to retrieve the co2 savings and equivenant trees planted and overlay those numbers on a graphic and upload them to the website.
|
||||||
|
|
||||||
|
# Dependancies
|
||||||
|
Python 3 and the packages `python-dotenv` and `Pillow`
|
||||||
|
The font `Biko_Regular.otf`
|
||||||
|
A `.png` graphic to write text on.
|
||||||
|
|
||||||
|
|
||||||
|
# Bulid Instructions
|
||||||
|
|
BIN
environmental_benefits_blank.png
Normal file
BIN
environmental_benefits_blank.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
14
requirements.txt
Normal file
14
requirements.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
asn1crypto==0.24.0
|
||||||
|
bcrypt==3.1.6
|
||||||
|
cffi==1.12.2
|
||||||
|
cryptography==2.4.2
|
||||||
|
idna==2.8
|
||||||
|
paramiko==2.4.2
|
||||||
|
Pillow==6.0.0
|
||||||
|
pkg-resources==0.0.0
|
||||||
|
pyasn1==0.4.5
|
||||||
|
pycparser==2.19
|
||||||
|
PyNaCl==1.3.0
|
||||||
|
python-dotenv==0.10.1
|
||||||
|
scp==0.13.2
|
||||||
|
six==1.12.0
|
51
solar_edge.py
Executable file
51
solar_edge.py
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import urllib.request
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from PIL import ImageFont
|
||||||
|
from PIL import ImageDraw
|
||||||
|
from PIL import Image
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from paramiko import SSHClient
|
||||||
|
from scp import SCPClient
|
||||||
|
|
||||||
|
## get JSON from solar edge server
|
||||||
|
url = os.getenv('URL')
|
||||||
|
infile = os.getenv('INFILE')
|
||||||
|
outfile = os.getenv('OUTFILE')
|
||||||
|
font_face = os.getenv('FONT_FACE')
|
||||||
|
ssh_host = os.getenv('SSH_HOST')
|
||||||
|
ssh_user = os.getenv('SSH_USER')
|
||||||
|
ssh_folder = os.getenv('SSH_FOLDER')
|
||||||
|
req = urllib.request.Request(url)
|
||||||
|
|
||||||
|
# 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']))
|
||||||
|
|
||||||
|
## create image for website
|
||||||
|
fill_color = "#298246"
|
||||||
|
xpos = 91
|
||||||
|
image = Image.open(infile)
|
||||||
|
font = ImageFont.truetype(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)
|
||||||
|
image.save(outfile)
|
||||||
|
|
||||||
|
## upload image to website
|
||||||
|
ssh = SSHClient()
|
||||||
|
ssh.load_system_host_keys()
|
||||||
|
ssh.connect(hostname=ssh_host, username=ssh_user)
|
||||||
|
|
||||||
|
scp = SCPClient(ssh.get_transport())
|
||||||
|
scp.put(outfile, ssh_folder)
|
||||||
|
scp.close()
|
||||||
|
ssh.close()
|
||||||
|
|
||||||
|
os.remove(outfile)
|
Loading…
Reference in New Issue
Block a user