add updated pi hole code

This commit is contained in:
brentru 2019-02-11 17:00:50 -05:00
parent 8aa75c5611
commit abd1d92b46

View file

@ -19,30 +19,39 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# This example is for use on (Linux) computers that are using CPython with
# Adafruit Blinka to support CircuitPython libraries. CircuitPython does
# not support PIL/pillow (python imaging library)!
# Import Python System Libraries
import json
import subprocess
import time
import Adafruit_SSD1306
# Import Requests Library
import requests
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
# Import Blinka
from board import SCL, SDA
import busio
import adafruit_ssd1306
# Import Python Imaging Library
from PIL import Image, ImageDraw, ImageFont
api_url = 'http://localhost/admin/api.php'
# Raspberry Pi pin configuration:
RST = None # on the PiOLED this pin isnt used
# Create the I2C interface.
i2c = busio.I2C(SCL, SDA)
# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
# Initialize library.
disp.begin()
# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height. Change these
# to the right size for your display!
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
# Clear display.
disp.clear()
disp.display()
disp.fill(0)
disp.show()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
@ -66,7 +75,7 @@ bottom = height - padding
x = 0
# Load nice silkscreen font
font = ImageFont.truetype("/home/pi/slkscr.ttf", 8)
font = ImageFont.truetype('/home/pi/slkscr.ttf', 8)
while True:
# Draw a black filled box to clear the image.
@ -75,18 +84,18 @@ while True:
# Shell scripts for system monitoring from here :
# https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
cmd = "hostname -I | cut -d\' \' -f1 | tr -d \'\\n\'"
IP = subprocess.check_output(cmd, shell=True)
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "hostname | tr -d \'\\n\'"
HOST = subprocess.check_output(cmd, shell=True)
HOST = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "top -bn1 | grep load | awk " \
"'{printf \"CPU Load: %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True)
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "free -m | awk 'NR==2{printf " \
"\"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True)
MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "df -h | awk '$NF==\"/\"{printf " \
"\"Disk: %d/%dGB %s\", $3,$2,$5}'"
Disk = subprocess.check_output(cmd, shell=True)
Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")
# Pi Hole data!
try:
@ -115,5 +124,5 @@ while True:
# Display image.
disp.image(image)
disp.display()
disp.show()
time.sleep(.1)