From 40ed4d688bb75800a56a4cecbc605d7cf212e1d5 Mon Sep 17 00:00:00 2001 From: drselump14 Date: Thu, 12 Jan 2017 12:13:50 +0900 Subject: [PATCH] get url from parsed tweet when entities url not found extras: set default browser using BROWSER variable --- rainbowstream/colorset/config | 2 ++ rainbowstream/rainbow.py | 10 ++++++---- setup.py | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config index 54b76ff0..c71028af 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -49,6 +49,8 @@ "IMAGE_MAX_HEIGHT" : 90, // Seconds to wait before displaying another tweet, will drop all tweets while waiting. "STREAM_DELAY" : 0, + // Set default browser for open link, default is w3m + "BROWSER": "w3m", // Stream config "USER_DOMAIN" : "userstream.twitter.com", "PUBLIC_DOMAIN" : "stream.twitter.com", diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index a499f957..c859916b 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -19,6 +19,8 @@ from twitter.oauth import OAuth, read_token_file from twitter.oauth_dance import oauth_dance from twitter.util import printNicely +from ttp import ttp +from subprocess import call from pocket import Pocket @@ -753,14 +755,14 @@ def urlopen(): return tid = c['tweet_dict'][int(g['stuff'])] tweet = t.statuses.show(id=tid) - urls = tweet['entities']['urls'] + # get url from entities. If it's not found get url from parsed tweet + urls = tweet['entities']['urls'] or ttp.Parser().parse(tweet).urls if not urls: printNicely(light_magenta('No url here @.@!')) - return else: for url in urls: - expanded_url = url['expanded_url'] - webbrowser.open(expanded_url) + expanded_url = url['expanded_url'] or url + call([c['BROWSER'],expanded_url]) except: debug_option() printNicely(red('Sorry I can\'t open url in this tweet.')) diff --git a/setup.py b/setup.py index 872dce18..971f5e89 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,8 @@ "twitter", "Pillow", "PySocks", - "pocket" + "pocket", + "twitter-text-python" ] # Default user (considers non virtualenv method)