Compare commits
2 Commits
f40662ab27
...
101f9e84af
| Author | SHA1 | Date | |
|---|---|---|---|
| 101f9e84af | |||
| 96b10e4358 |
40
imagegen.py
40
imagegen.py
@@ -1,36 +1,52 @@
|
|||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
import datetime
|
import datetime
|
||||||
import pytz
|
import pytz
|
||||||
import asyncio
|
#import asyncio
|
||||||
import google_weather
|
import google_weather
|
||||||
import mlb
|
import mlb
|
||||||
#from getweather import getweather
|
#from getweather impor]t getweather
|
||||||
# create an image
|
# create an image
|
||||||
out = Image.new("L", (800, 480),255)
|
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
|
# get a font
|
||||||
fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",25)
|
fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",25)
|
||||||
fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",35)
|
fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",35)
|
||||||
|
HeightNormal = 25
|
||||||
|
HeightBold = 35
|
||||||
|
MarginLeft = 1
|
||||||
|
MarginIndent = 5
|
||||||
# get a drawing context
|
# get a drawing context
|
||||||
d = ImageDraw.Draw(out)
|
d = ImageDraw.Draw(out)
|
||||||
|
|
||||||
# create text
|
# create text
|
||||||
txt1 = datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%A %B %d, %Y %I:%M %p')
|
txt1 = datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%A %B %d, %Y')
|
||||||
# draw multiline text
|
# draw multiline text
|
||||||
d.multiline_text((1, 1), txt1, font=fntBold, fill=0)
|
d.multiline_text((displaysize[0]/2, row), txt1, font=fntBold, fill=0, anchor = "ma") #, align="center")
|
||||||
#txt2 = "This is the day that the LORD has made\nWe will rejoice and be glad in it."
|
row += HeightBold
|
||||||
#txt2 = asyncio.run(getweather())
|
|
||||||
d.multiline_text((1, 35), "Weather:", font=fnt, fill=0)
|
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
|
||||||
|
|
||||||
|
d.multiline_text((MarginLeft, row), "Weather:", font=fnt, fill=0, anchor = "la")
|
||||||
|
row += HeightNormal
|
||||||
try:
|
try:
|
||||||
weather = google_weather.get_google_weather()
|
weather = google_weather.get_google_weather()
|
||||||
txt2 = "Current: "+weather["current"] \
|
txt2 = "Current: "+weather["current"] \
|
||||||
+"\nToday's forecast: "+weather["forecast_today"] \
|
+"\nToday's forecast: "+weather["forecast_today"] \
|
||||||
+"\nTomorrow: "+weather["forecast_tomorrow"]
|
+"\nTomorrow: "+weather["forecast_tomorrow"]
|
||||||
except: # Assume the weather API blew up
|
except: # Assume the weather API blew up
|
||||||
txt2 = "Problem getting weather"
|
txt2 = "Problem getting weather (from ImageGen)"
|
||||||
d.multiline_text((1, 60), txt2, font=fnt, fill=0)
|
d.multiline_text((MarginIndent, row), txt2, font=fnt, fill=0, anchor = "la")
|
||||||
d.multiline_text((1, 135), "Pirates:", font=fnt, fill=0)
|
row += 3*HeightNormal
|
||||||
d.multiline_text((3,160), mlb.get_pirates(), font=fnt, fill=0)
|
|
||||||
|
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
|
||||||
|
|
||||||
out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG")
|
out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG")
|
||||||
#out.show()
|
#out.show()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user