From 05a4e9b6e4ccf6c2b22f9cd74695549d6758979d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Tue, 24 Jan 2017 08:15:49 -0600 Subject: [PATCH] Fixed a bug in long tweet parsing. Fixes #103 --- doc/changelog.md | 4 ++++ src/long_tweets/twishort.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 9fb06110..9581b75a 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,10 @@ ## 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) + +## Changes in version 0.88 and 0.89 + * Fixed more issues with streams and reconnections. * newer updates will indicate the release date in the updater. * Changes to keystrokes are reflected in keystroke editor automatically. diff --git a/src/long_tweets/twishort.py b/src/long_tweets/twishort.py index da6be40f..8614d8b5 100644 --- a/src/long_tweets/twishort.py +++ b/src/long_tweets/twishort.py @@ -33,17 +33,23 @@ def is_long(tweet): long = False for url in range(0, len(tweet["entities"]["urls"])): try: - if "twishort.com" in tweet["entities"]["urls"][url]["expanded_url"]: + if tweet["entities"]["urls"][url] != None and "twishort.com" in tweet["entities"]["urls"][url]["expanded_url"]: long = get_twishort_uri(tweet["entities"]["urls"][url]["expanded_url"]) except IndexError: pass + # sometimes Twitter returns URL's with None objects, so let's take it. + # see https://github.com/manuelcortez/TWBlue/issues/103 + except TypeError: + pass if long == False and tweet.has_key("retweeted_status"): for url in range(0, len(tweet["retweeted_status"]["entities"]["urls"])): try: - if "twishort.com" in tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]: + if tweet["entities"]["urls"][url] != None and "twishort.com" in tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]: long = get_twishort_uri(tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]) except IndexError: pass + except TypeError: + pass return long def get_full_text(uri):