orakaro / rainbowstream

A smart and nice Twitter client on terminal written in Python.
https://github.com/orakaro/rainbowstream
MIT License
3.55k stars 261 forks source link

User is unable to open url's shortened by Twitters URL shortener #270

Open bcaccia opened 6 years ago

bcaccia commented 6 years ago

Repro:

  1. Launch rainbowstream

  2. Locate a tweet that contains a URL shortened by Twitters URL shortener(https://t.co/wNYPltI7ll ) image

  3. Type open id#

Expected:

Bug:

Additional Notes:

movalex commented 6 years ago

can not confirm this, since it is working correctly on 1.3.8. Did you try to upgrade?

bcaccia commented 6 years ago

I upgraded to rainbowstream v1.3.9 using: sudo pip install -U rainbowstream

I am able to reproduce the same behavior.

To rule out the terminal, I tried both Konsole and st terminal. The same bug behavior was seen in both.

movalex commented 6 years ago

Update: Had to change my previous comment because I also followed that @HorrorAudio account and found out that the t.co links it is posting do not open for me too. Not sure what it is related to... But obviously urlopen function returns urls = None, hence the error. Would like to see developer answer too.

  HorrorAudio @HorrorAudio 11 minutes ago
  ♺:1 ♥:0 id:12 via RoundTeam
  RT @RifaOlivier: What makes you stop writing variations, new harmony, trying different path for a track ? What makes you say stop writin, let's produce, now ?
  Is it time schedule ? enough material ? Faith ?
  #composition #composer #GameAudio https://t.co/SEaTJV2BNw

  [@movalex]: open 12
  No url here @.@!
nstr10 commented 6 years ago

It looks like the URLs are provided by Twitter's API library, so this may need to be addressed upstream.

RandomCore commented 5 years ago

I don't know any Python, but I was able to figure out some workaround for the "No url here @.@" problem. It seems the problem is based on the place of the shown URL in the Twitter API return value for a tweet. So adding some code in rainbow.py function urlopen() to find different places for the URLs does the magic:

def urlopen():
    ...
    urls = tweet['entities']['urls']
    if not urls:
        try:
            urls = tweet['entities']['media']
        except:
            urls = {}
    if not urls:
        try:                                                                                    
            urls = tweet['retweeted_status']['quoted_status']['entities']['urls']               
        except:                                                                                 
            urls = {}                                                                           

    if not urls:                                                                                
        printNicely(light_magenta('No url here @.@!'))                                          
        return
    ...

I don't know, if I have found all places for URLs. Maybe someone can improve on this.