Skip to content

Commit

Permalink
provide url from parsed tweet when entities url not found
Browse files Browse the repository at this point in the history
extras:
- user could set default browser when open link by set BROWSER variable
  on config
- default browser is w3m
  • Loading branch information
drselump14 committed Jan 12, 2017
1 parent 88a1cec commit 1f2829d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions rainbowstream/colorset/config
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions rainbowstream/rainbow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.'))
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"twitter",
"Pillow",
"PySocks",
"pocket"
"pocket",
"twitter-text-python"
]

# Default user (considers non virtualenv method)
Expand Down

0 comments on commit 1f2829d

Please sign in to comment.