72 lines
2.7 KiB
Python
72 lines
2.7 KiB
Python
from PIL import Image, ImageDraw, ImageFont
|
|
import datetime
|
|
import pytz
|
|
import google_weather
|
|
import mlb
|
|
import gcal
|
|
|
|
fontBaseHeight = 25
|
|
fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",fontBaseHeight)
|
|
fntSmall = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",fontBaseHeight-10)
|
|
fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",fontBaseHeight)
|
|
fntBigBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",fontBaseHeight+5)
|
|
|
|
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
|
|
#HeightNormal = 25
|
|
#HeightBold = 35
|
|
MarginLeft = 1
|
|
MarginIndent = 10
|
|
# get a drawing context
|
|
d = ImageDraw.Draw(out)
|
|
|
|
# create text
|
|
txt1a = "As of "+datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%I:%M %p')
|
|
#row = WriteTextBlock(txt1a,d,fnt,displaysize[0]/2,row,"ma")
|
|
rowThrowAway = WriteTextBlock(txt1a,d,fntSmall,displaysize[0],row,"ra")
|
|
|
|
txt1 = datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%A %B %d, %Y')
|
|
# draw multiline text
|
|
row = WriteTextBlock(txt1,d,fntBigBold,displaysize[0]/2,row,"ma")
|
|
|
|
|
|
row = WriteTextBlock("Weather",d,fntBold,MarginLeft,row,"la")
|
|
try:
|
|
weather = google_weather.get_google_weather()
|
|
txt2 = "Current: "+weather["current"] \
|
|
+"\nToday's forecast: "+weather["forecast_today"] \
|
|
+"\nTomorrow: "+weather["forecast_tomorrow"]
|
|
except: # Assume the weather API blew up
|
|
txt2 = "Problem getting weather (from ImageGen)"
|
|
row = WriteTextBlock(txt2,d,fnt,MarginIndent,row,"la")
|
|
|
|
row = WriteTextBlock("Pirates",d,fntBold,MarginLeft,row,"la")
|
|
row = WriteTextBlock(mlb.get_pirates(),d,fnt,MarginIndent,row,"la")
|
|
|
|
appointments = gcal.main()
|
|
apptxt = ""
|
|
for event in appointments:
|
|
#start = event["start"].get("dateTime", event["start"].get("date"))
|
|
#apptxt+= start+": "+event["summary"]+" (from "+event["calendarname"]+")\n"
|
|
if event["prettytime"]:
|
|
apptxt+= event["prettytime"]+": "+event["summary"]+" (from "+event["calendarname"]+")\n"
|
|
else:
|
|
apptxt+= event["summary"]+" (from "+event["calendarname"]+")\n"
|
|
|
|
row = WriteTextBlock("Appointments",d,fntBold,MarginLeft,row,"la")
|
|
row = WriteTextBlock(apptxt,d,fnt,MarginIndent,row,"la")
|
|
|
|
|
|
row = WriteTextBlock("========== End =========",d,fnt,MarginLeft,row,"la")
|
|
|
|
out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG")
|