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 f522b6b commit 5bff314
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions otbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,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 5bff314

Please sign in to comment.