Compare commits

...

2 Commits

Author SHA1 Message Date
e3338fc3f6 Cleaned up messyness 2026-05-26 15:14:50 +00:00
e3e1425f5a Messy version of bounding box 2026-05-26 15:07:55 +00:00
2 changed files with 21 additions and 16 deletions

2
.gitignore vendored
View File

@@ -5,3 +5,5 @@ __pycache__
old
Scripts
pyvenv.cfg
share
*.swp

View File

@@ -1,18 +1,25 @@
from PIL import Image, ImageDraw, ImageFont
import datetime
import pytz
#import asyncio
import google_weather
import mlb
#from getweather impor]t getweather
fontBaseHeight = 25
fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",fontBaseHeight)
fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",fontBaseHeight)
fntBigBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",fontBaseHeight+10)
def WriteTextBlock(text, context, font = fnt, column=0, row=0, anchor = "la"):
context.multiline_text((column, row), text, font=font, fill=0, anchor = anchor)
boundingBox = context.multiline_textbbox((column,row),text,font=font,anchor=anchor)
return boundingBox[3]
# create an image
displaysize = [800,480] # width, height - same as text writing features
row = 0 # current row to write at
out = Image.new("L", (displaysize[0], displaysize[1]),255)
# get a font
fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",25)
fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",35)
HeightNormal = 25
HeightBold = 35
MarginLeft = 1
@@ -23,15 +30,12 @@ d = ImageDraw.Draw(out)
# create text
txt1 = datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%A %B %d, %Y')
# draw multiline text
d.multiline_text((displaysize[0]/2, row), txt1, font=fntBold, fill=0, anchor = "ma") #, align="center")
row += HeightBold
row = WriteTextBlock(txt1,d,fntBigBold,displaysize[0]/2,row,"ma")
txt1a = "As of "+datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%I:%M %p')
d.multiline_text((displaysize[0]/2, row), txt1a, font=fnt, fill=0, anchor = "ma") #, align="center")
row += HeightNormal
row = WriteTextBlock(txt1a,d,fnt,displaysize[0]/2,row,"ma")
d.multiline_text((MarginLeft, row), "Weather:", font=fnt, fill=0, anchor = "la")
row += HeightNormal
row = WriteTextBlock("Weather",d,fnt,MarginLeft,row,"la")
try:
weather = google_weather.get_google_weather()
txt2 = "Current: "+weather["current"] \
@@ -39,13 +43,12 @@ try:
+"\nTomorrow: "+weather["forecast_tomorrow"]
except: # Assume the weather API blew up
txt2 = "Problem getting weather (from ImageGen)"
d.multiline_text((MarginIndent, row), txt2, font=fnt, fill=0, anchor = "la")
row += 3*HeightNormal
row = WriteTextBlock(txt2,d,fnt,MarginIndent,row,"la")
d.multiline_text((MarginLeft,row), "Pirates:", font=fnt, fill=0, anchor = "la")
row += HeightNormal
d.multiline_text((MarginIndent,row), mlb.get_pirates(), font=fnt, fill=0, anchor = "la")
row += 3*HeightNormal
row = WriteTextBlock("Pirates",d,fnt,MarginLeft,row,"la")
row = WriteTextBlock(mlb.get_pirates(),d,fnt,MarginIndent,row,"la")
row = WriteTextBlock("========== End =========",d,fnt,MarginLeft,row,"la")
out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG")
#out.show()