From c136c50afcbe7df41b8eca940a7ee6574bbecdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Fri, 24 Feb 2017 08:49:54 -0600 Subject: [PATCH] Add image description from retweets. Fixes #119 --- doc/changelog.md | 11 ++++++----- src/controller/messages.py | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 84d78292..4828a32f 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,11 +2,12 @@ ## changes in this version -* Fixed a bug in long tweet parsing that was making TWBlue to disconnect the streaming API. [#103](https://github.com/manuelcortez/TWBlue/issues/103) -* Now OCR will work in images from retweets. It fixes a bug where TWBlue was detecting images but couldn't apply OCR on them. [#105](https://github.com/manuelcortez/TWBlue/issues/105) -* TWBlue won't try to load tweets already deleted, made with Twishort. Before, if someone posted a long tweet but deleted it in the Twishort's site, TWBlue was trying to load the tweet and it was causing problems in all the client. [#113](https://github.com/manuelcortez/TWBlue/issues/113) -* TWBlue shows an error message when you try to view the profile of a user that does not exist or has been suspended. [#114,](https://github.com/manuelcortez/TWBlue/issues/114) [#115](https://github.com/manuelcortez/TWBlue/issues/115) -* The spellchecker module should select the right language when is set to "user default". [#117](https://github.com/manuelcortez/TWBlue/issues/117) +* Fixed a bug in long tweet parsing that was making TWBlue to disconnect the streaming API. ([#103](https://github.com/manuelcortez/TWBlue/issues/103)) +* Now OCR will work in images from retweets. It fixes a bug where TWBlue was detecting images but couldn't apply OCR on them. ([#105](https://github.com/manuelcortez/TWBlue/issues/105)) +* TWBlue won't try to load tweets already deleted, made with Twishort. Before, if someone posted a long tweet but deleted it in the Twishort's site, TWBlue was trying to load the tweet and it was causing problems in all the client. ([#113](https://github.com/manuelcortez/TWBlue/issues/113)) +* TWBlue shows an error message when you try to view the profile of an user that does not exist or has been suspended. ([#114,](https://github.com/manuelcortez/TWBlue/issues/114) [#115](https://github.com/manuelcortez/TWBlue/issues/115)) +* The spellchecker module should select the right language when is set to "user default". ([#117](https://github.com/manuelcortez/TWBlue/issues/117)) +* Image description will be displayed in retweets too. ([#119](https://github.com/manuelcortez/TWBlue/issues/119)) ## Changes in version 0.88 and 0.89 diff --git a/src/controller/messages.py b/src/controller/messages.py index 1662e525..a9bf2bde 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -219,6 +219,10 @@ class viewTweet(basicTweet): for z in tweetList[i]["extended_entities"]["media"]: if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: image_description.append(z["ext_alt_text"]) + if tweetList[i].has_key("retweeted_status") and tweetList[i]["retweeted_status"].has_key("extended_entities") and tweetList[i]["retweeted_status"]["extended_entities"].has_key("media"): + for z in tweetList[i]["retweeted_status"]["extended_entities"]["media"]: + if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: + image_description.append(z["ext_alt_text"]) # set rt and likes counters. rt_count = str(tweet["retweet_count"]) favs_count = str(tweet["favorite_count"]) @@ -241,6 +245,10 @@ class viewTweet(basicTweet): for z in tweet["extended_entities"]["media"]: if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: image_description.append(z["ext_alt_text"]) + if tweet.has_key("retweeted_status") and tweet["retweeted_status"].has_key("extended_entities") and tweet["retweeted_status"]["extended_entities"].has_key("media"): + for z in tweet["retweeted_status"]["extended_entities"]["media"]: + if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: + image_description.append(z["ext_alt_text"]) self.message = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8")) self.message.set_title(len(text)) [self.message.set_image_description(i) for i in image_description]