works with pyinstaller
This commit is contained in:
parent
52442f3cdc
commit
ba56145e86
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
.direnv/*
|
.direnv/*
|
||||||
__pycache__/*
|
__pycache__/*
|
||||||
|
build/*
|
||||||
|
dist/*
|
||||||
|
venv/*
|
||||||
.env
|
.env
|
||||||
|
15
README.md
15
README.md
@ -29,15 +29,27 @@ pip install -r requirements.txt
|
|||||||
|
|
||||||
edit `.env` and update accordingly
|
edit `.env` and update accordingly
|
||||||
|
|
||||||
|
add to user crontab to update site every 5 minutes
|
||||||
|
```
|
||||||
|
*/5 * * * * cd ~/python/solar_edge && direnv exec . python solar_edge.py > /dev/null 2>&1
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# Create pyinstaller
|
||||||
|
```
|
||||||
|
pyinstaller --onefile solar_edge.spec
|
||||||
|
```
|
||||||
|
|
||||||
add to user crontab to update site every 5 minutes
|
add to user crontab to update site every 5 minutes
|
||||||
```
|
```
|
||||||
05 * * * * cd ~/python/solar_edge && direnv exec . python solar_edge.py > /dev/null 2>&1
|
*/5 * * * * ~/bin/solar_edge > /dev/null 2>&1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Sample .env if installed on the server
|
# Sample .env if installed on the server
|
||||||
```
|
```
|
||||||
SSH_HOST=
|
SSH_HOST=
|
||||||
|
SSH_PORT=
|
||||||
SSH_USER=
|
SSH_USER=
|
||||||
SSH_FOLDER=/var/www/wordpress
|
SSH_FOLDER=/var/www/wordpress
|
||||||
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
|
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
|
||||||
@ -49,6 +61,7 @@ FONT_FACE=Biko_Regular.otf
|
|||||||
# Sample .env file for scp
|
# Sample .env file for scp
|
||||||
```
|
```
|
||||||
SSH_HOST=myserver.com
|
SSH_HOST=myserver.com
|
||||||
|
SSH_PORT=22
|
||||||
SSH_USER=www-data
|
SSH_USER=www-data
|
||||||
SSH_FOLDER=/var/www/wordpress
|
SSH_FOLDER=/var/www/wordpress
|
||||||
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
|
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
SSH_HOST=myserver.com
|
SSH_HOST=myserver.com
|
||||||
|
SSH_PORT=22
|
||||||
SSH_USER=www-data
|
SSH_USER=www-data
|
||||||
SSH_FOLDER=/var/www/wordpress
|
SSH_FOLDER=/var/www/wordpress
|
||||||
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
|
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
altgraph==0.17
|
||||||
asn1crypto==0.24.0
|
asn1crypto==0.24.0
|
||||||
bcrypt==3.1.6
|
bcrypt==3.1.6
|
||||||
cffi==1.12.2
|
cffi==1.12.2
|
||||||
@ -8,6 +9,8 @@ Pillow==6.0.0
|
|||||||
pkg-resources==0.0.0
|
pkg-resources==0.0.0
|
||||||
pyasn1==0.4.5
|
pyasn1==0.4.5
|
||||||
pycparser==2.19
|
pycparser==2.19
|
||||||
|
pyinstaller==4.0
|
||||||
|
pyinstaller-hooks-contrib==2020.9
|
||||||
PyNaCl==1.3.0
|
PyNaCl==1.3.0
|
||||||
python-dotenv==0.10.1
|
python-dotenv==0.10.1
|
||||||
scp==0.13.2
|
scp==0.13.2
|
||||||
|
@ -11,12 +11,24 @@ from dotenv import load_dotenv
|
|||||||
from paramiko import SSHClient
|
from paramiko import SSHClient
|
||||||
from scp import SCPClient
|
from scp import SCPClient
|
||||||
|
|
||||||
|
#### HEAR BE DRAGONS
|
||||||
|
# set python environment
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
bundle_dir = sys._MEIPASS
|
||||||
|
else:
|
||||||
|
# we are running in a normal Python environment
|
||||||
|
bundle_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
# load environmental variables
|
||||||
|
load_dotenv(bundle_dir + "/.env")
|
||||||
|
|
||||||
## get JSON from solar edge server
|
## get JSON from solar edge server
|
||||||
url = os.getenv('URL')
|
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')
|
||||||
ssh_host = os.getenv('SSH_HOST')
|
ssh_host = os.getenv('SSH_HOST')
|
||||||
|
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)
|
req = urllib.request.Request(url)
|
||||||
@ -31,8 +43,8 @@ trees = str(round(cont['envBenefits']['treesPlanted']))
|
|||||||
## create image for website
|
## create image for website
|
||||||
fill_color = "#298246"
|
fill_color = "#298246"
|
||||||
xpos = 91
|
xpos = 91
|
||||||
image = Image.open(infile)
|
image = Image.open(bundle_dir + "/" + infile)
|
||||||
font = ImageFont.truetype(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, 81), co2, font=font, fill=fill_color)
|
||||||
@ -44,7 +56,7 @@ image.save(outfile)
|
|||||||
if ssh_host:
|
if ssh_host:
|
||||||
ssh = SSHClient()
|
ssh = SSHClient()
|
||||||
ssh.load_system_host_keys()
|
ssh.load_system_host_keys()
|
||||||
ssh.connect(hostname=ssh_host, username=ssh_user)
|
ssh.connect(hostname=ssh_host, port=ssh_port, username=ssh_user)
|
||||||
|
|
||||||
scp = SCPClient(ssh.get_transport())
|
scp = SCPClient(ssh.get_transport())
|
||||||
scp.put(outfile, ssh_folder)
|
scp.put(outfile, ssh_folder)
|
||||||
|
33
solar_edge.spec
Normal file
33
solar_edge.spec
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(['solar_edge.py'],
|
||||||
|
pathex=['/home/fwarren/builds/solar_edge'],
|
||||||
|
binaries=[],
|
||||||
|
datas=[('.env','.'),('Biko_Regular.otf','.'),('environmental_benefits_blank.png','.')],
|
||||||
|
hiddenimports=[],
|
||||||
|
hookspath=[],
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher,
|
||||||
|
noarchive=False)
|
||||||
|
pyz = PYZ(a.pure, a.zipped_data,
|
||||||
|
cipher=block_cipher)
|
||||||
|
exe = EXE(pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name='solar_edge',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
upx_exclude=[],
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=True )
|
Loading…
Reference in New Issue
Block a user