Skip to content

Commit

Permalink
Handle the case when an image is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
yatch committed Jun 3, 2019
1 parent feba023 commit 09c9134
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions otbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import base64
import argparse
import logging
import sys

try:
from PIL import Image
Expand Down Expand Up @@ -126,10 +127,19 @@ def _mqtt_handler_picturetoscreen(self, deviceType, deviceId, payload):
{{TESTBED}}/deviceType/box/deviceId/box1/cmd/picturetoscreen
'''
assert deviceType==DEVICETYPE_BOX
image = Image.open(requests.get(json.loads(payload)['url'], stream=True).raw)
image.thumbnail((480,320),Image.ANTIALIAS)
self._otbox.change_image_queue.put(image)
self._otbox.change_image_queue.join()
try:
image_url = json.loads(payload)['url']
response = requests.get(image_url, stream=True)
image = Image.open(response.raw)
except IOError:
# the image is not available now; skip this one
print('image at {0} is not available, '.format(image_url)
+ 'HTTP response code {0}'.format(response.status_code))
sys.stdout.flush()
else:
image.thumbnail((480,320),Image.ANTIALIAS)
self._otbox.change_image_queue.put(image)
self._otbox.change_image_queue.join()
return {}

def _mqtt_handler_colortoscreen(self, deviceType, deviceId, payload):
Expand Down

0 comments on commit 09c9134

Please sign in to comment.