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) * bash.rc (https://github.com/direnv/direnv/wiki/Python#bash)
* venv (https://github.com/direnv/direnv/wiki/Python#venv-stdlib-module) * 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. If `ssh_host` is blank will copy file locally instead of scping file to sever. To scp valid sshkeys are required.
`
import shutil
...
shutil.copy2(out_file, '/var/www/')
`
# Bulid Instructions # Bulid Instructions
assumes installed to `~/python/solar_edge` 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 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_HOST=myserver.com
SSH_USER= SSH_USER=www-data
SSH_FOLDER= 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=
INFILE=environmental_benefits_blank.png INFILE=environmental_benefits_blank.png
OUTFILE= OUTFILE=solar.png
FONT_FACE=Biko_Regular.otf FONT_FACE=Biko_Regular.otf

View File

@ -3,6 +3,7 @@
import urllib.request import urllib.request
import json import json
import os import os
import shutil
from PIL import ImageFont from PIL import ImageFont
from PIL import ImageDraw from PIL import ImageDraw
from PIL import Image from PIL import Image
@ -38,14 +39,18 @@ draw.text((xpos, 81), co2, font=font, fill=fill_color)
draw.text((xpos, 157), trees, font=font, fill=fill_color) draw.text((xpos, 157), trees, font=font, fill=fill_color)
image.save(outfile) 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()) ## upload image to website or copy to folder
scp.put(outfile, ssh_folder) if ssh_host:
scp.close() ssh = SSHClient()
ssh.close() 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()
else:
shutil.copy2(outfile, ssh_folder)
os.remove(outfile) os.remove(outfile)