From 632b69f75b81cab1c58fb6845ac1ad3087ce8e97 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Thu, 10 May 2018 07:30:14 -0700 Subject: [PATCH] attempt to handle lack of image info in event #32 --- appservice.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/appservice.py b/appservice.py index 95a7fc6..60d0698 100644 --- a/appservice.py +++ b/appservice.py @@ -65,29 +65,30 @@ def on_receive_events(transaction): value = {"type": "photo", "version": "1.0"} value["title"] = event['content']['body'] value["url"] = imgurl - if 'w' in event['content']['info']: - value["width"] = event['content']['info']['w'] - else: - value["width"] = 200 - if 'h' in event['content']['info']: - value["height"] = event['content']['info']['h'] - else: - value["height"] = 200 - if 'thumbnail_info' in event['content']['info']: - thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:] - value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w'] - value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h'] - value["thumbnail_url"] = thmburl - else: + if 'info' in event['content']: if 'w' in event['content']['info']: - value["thumbnail_width"] = event['content']['info']['w'] + value["width"] = event['content']['info']['w'] else: - value["thumbnail_width"] = 200 + value["width"] = 200 if 'h' in event['content']['info']: - value["thumbnail_height"] = event['content']['info']['h'] + value["height"] = event['content']['info']['h'] else: - value["thumbnail_height"] = 200 - value["thumbnail_url"] = imgurl + value["height"] = 200 + if 'thumbnail_info' in event['content']['info']: + thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:] + value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w'] + value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h'] + value["thumbnail_url"] = thmburl + else: + if 'w' in event['content']['info']: + value["thumbnail_width"] = event['content']['info']['w'] + else: + value["thumbnail_width"] = 200 + if 'h' in event['content']['info']: + value["thumbnail_height"] = event['content']['info']['h'] + else: + value["thumbnail_height"] = 200 + value["thumbnail_url"] = imgurl rawitem = {"type": "io.pnut.core.oembed", "value": value} embed = [rawitem] if user: