Sleepy Weim

Python: Fetch Weather for ActionTiles

So, this is pulling together the other two scripts I wrote (download and crop images). Really, this is just for you to see the iterations of what I did before I got here. I could have just jumped you straight to here, but it helps to see the individual components before getting more complicated in a single script. The standard walk before you run.

This script takes the download script, the crop script, and then adds some new statements at the bottom for copying the files. The paths are relative to the script files themselves, so we need to take the final products and save them out into the web folder path.

Once you have the scripts working, you have to tweak them to save into the web server folder structure. Otherwise, ActionTiles couldn’t see them, since it only speaks URL. As I mentioned previously, my Synology is running the scripts, as well as hosting a web server. This means my paths are all relative to that folder structure. In your case, this may be the case, or may be different computers; adjust your paths accordingly.

import urllib
import os
from PIL import Image

# #####
#
# Retrieve the images
#
# #####
url_3DayPhilly = "https://www.nbcphiladelphia.com/assets/weather/wcau/3day1.png"
url_3DayShore = "https://www.nbcphiladelphia.com/assets/weather/wcau/3day2.png"
url_LocalTemps = "https://www.nbcphiladelphia.com/assets/weather/wcau/webdvcurrents.png"

webimg = urllib.URLopener()
webimg.retrieve(url_3DayPhilly,"3day1.png")
webimg.retrieve(url_3DayShore,"3day2.png")
webimg.retrieve(url_LocalTemps,"localtemps.png")

# #####
#
# Crop and combine images
#
# #####

#
# Crop first image
#
img = Image.open("3day1.png")
area = (405, 120, 1450, 675)

cropimg = img.crop(area)
cropimg.save("3day1_small.png")

#
# Crop second image
#
img = Image.open("3day2.png")
area = (405, 670, 1450, 905)

cropimg = img.crop(area)
cropimg.save("3day2_small.png")

#
# Crop local temps image
#
img = Image.open("localtemps.png")
area = (460, 110, 1255, 900)

cropimg = img.crop(area)
cropimg.save("localtemps_small.png")

#
# Combine both into single image
#
img1 = Image.open("3day1_small.png")
img2 = Image.open("3day2_small.png")
newimg = Image.new("RGB", (1045, 790))

newimg.paste(img1, (0,0))
newimg.paste(img2, (0,555))
newimg.save("3day.png")

# #####
#
# Copy image to web directory
#
# #####
newimg.save("/volume1/web/actiontiles/3day.png")
cropimg.save("/volume1/web/actiontiles/localtemps.png")

1 thought on “Python: Fetch Weather for ActionTiles

Leave a Reply

Your email address will not be published. Required fields are marked *