added scp/local code

This commit is contained in:
Fred Warren 2019-04-15 16:26:14 -07:00
parent a62c051bed
commit 13082e3b5d
3 changed files with 42 additions and 18 deletions

View File

@ -12,12 +12,8 @@ The package direnv and the follwing changes to the user account:
* bash.rc (https://github.com/direnv/direnv/wiki/Python#bash)
* venv (https://github.com/direnv/direnv/wiki/Python#venv-stdlib-module)
Assumes the use of direnv and ssh keys setup to upload graphic to website. If hosted on the website the ssh/scp portion can be replace with a copy.
`
import shutil
...
shutil.copy2(out_file, '/var/www/')
`
If `ssh_host` is blank will copy file locally instead of scping file to sever. To scp valid sshkeys are required.
# Bulid Instructions
assumes installed to `~/python/solar_edge`
@ -38,3 +34,26 @@ 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
```
# Sample .env if installed on the server
```
SSH_HOST=
SSH_USER=
SSH_FOLDER=/var/www/wordpress
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
INFILE=environmental_benefits_blank.png
OUTFILE=solar.png
FONT_FACE=Biko_Regular.otf
```
# Sample .env file for scp
```
SSH_HOST=myserver.com
SSH_USER=www-data
SSH_FOLDER=/var/www/wordpress
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
INFILE=environmental_benefits_blank.png
OUTFILE=solar.png
FONT_FACE=Biko_Regular.otf
```

View File

@ -1,7 +1,7 @@
SSH_HOST=
SSH_USER=
SSH_FOLDER=
SSH_HOST=myserver.com
SSH_USER=www-data
SSH_FOLDER=/var/www/wordpress
URL=https://monitoringapi.solaredge.com/site/55555/envBenefits?systemUnits=Imperial&api_key=
INFILE=environmental_benefits_blank.png
OUTFILE=
OUTFILE=solar.png
FONT_FACE=Biko_Regular.otf

View File

@ -3,6 +3,7 @@
import urllib.request
import json
import os
import shutil
from PIL import ImageFont
from PIL import ImageDraw
from PIL import Image
@ -38,7 +39,9 @@ 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
## upload image to website or copy to folder
if ssh_host:
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect(hostname=ssh_host, username=ssh_user)
@ -47,5 +50,7 @@ scp = SCPClient(ssh.get_transport())
scp.put(outfile, ssh_folder)
scp.close()
ssh.close()
else:
shutil.copy2(outfile, ssh_folder)
os.remove(outfile)