Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Support for flairs #28

Closed
michael-lazar opened this issue Mar 6, 2015 · 9 comments
Closed

Support for flairs #28

michael-lazar opened this issue Mar 6, 2015 · 9 comments

Comments

@michael-lazar
Copy link
Owner

Would be nice if we could support flairs from different subreddits. Would look something like

screenshot from 2015-03-05 20 20 33

@tobywhughes
Copy link
Contributor

Fount this in PRAW's code overview. May be helpful:

 get_flair(subreddit, redditor) 
     Return the flair for a user on the given subreddit.

     Requires the modflair oauth scope or user/password authentication as a mod of the subreddit.

     Parameters:
    •subreddit – Can be either a Subreddit object or the name of a subreddit.
    •redditor – Can be either a Redditor object or the name of a redditor.

     Returns:
     None if the user doesn’t exist, otherwise a dictionary containing the keys flair_css_class, flair_text, and user.

@shawnhind
Copy link
Contributor

I`m going to take a look at doing this.

@shawnhind
Copy link
Contributor

Hey @michael-lazar, I've been looking at doing this but I'm having trouble finding where the comments and submission text are actually set / drawn to the screen. In the submissions.py module there are functions such as draw_submission and draw_comment. In these there are variables called text which seem to then be put into the curses screen. I've tried adding extra text to these text variables just to see what that would affect and it actually did nothing. Am I misunderstanding what this section of the code does?

@michael-lazar
Copy link
Owner Author

That sounds like you're doing it correctly. Keep in mind that subreddit.py controls the main page, and submission.py controls the comments page. If you're trying to change the behavior of the main page, you need to look at subreddit.draw_item(). That being said, changing the text to something like

text = '{author} test_flair'.format(**data)

should produce a visible output. If it still doesn't, my guess is that python is grabbing files from a different location than you are expecting. If so let me know and we can walk through setting everything up.

@shawnhind
Copy link
Contributor

Yeah I think Python must be grabbing files from a different place. Should I perhaps uninstall the system wide rtv that I installed via package manager? Or what would you suggest doing?

On Mar 9, 2015, at 18:22, michael-lazar notifications@github.com wrote:

That sounds like you're doing it correctly. Keep in mind that subreddit.py controls the main page, and submission.py controls the comments page. If you're trying to change the behavior of the main page, you need to look at subreddit.draw_item(). That being said, changing the text to something like

text = '{author} test_flair'.format(**data)
should produce a visible output. If it still doesn't, my guess is that python is grabbing files from a different location than you are expecting. If so let me know and we can walk through setting everything up.


Reply to this email directly or view it on GitHub.

@michael-lazar
Copy link
Owner Author

Here's what I've been doing lately. First make sure that your repo is up-to-date.

  1. cd into the top directory (the one with setup.py and README.rst)
  2. type python -m rtv

Explanation:
The -m rtv is shorthand for typing out python rtv/__main__.py. When python sees the lines

from rtv.main import main
main()

inside of __main__.py, it will search the current directory for valid packages first, and then if it doesn't find anything it will start searching through site-packages and pip installs. Since the current directory has a folder called rtv/ with an __init__.py inside of it, that is the one that python will import.

@shawnhind
Copy link
Contributor

Using python -m totally fixed my problem. I was running using python rtv/main.py before and for whatever reason it doesn't import from the correct place when running it that way. Thanks for giving me a hand on this, I'm going to continue working away on adding this feature.

@shawnhind
Copy link
Contributor

I'm having an issue where as soon as I add a get_flair() call to content.py the program starts immediately crashing with the error message "Could not reach /r/front". My initial thought was that an exception was being thrown and getting caught by a block that does that but I haven't been able to figure out what's happening. get_flair documentation doesn't indicate that it would be throwing any exceptions and should just be returning None if the user or subreddit was not found. Do you have any idea why adding get_flair calls into the split_submission method in content.py would be causing it to crash with this message? (Note that even when get_flair is called for ANY subreddit, it always says "Could not reach /r/front")

Here is the rough block of code that I wrote for getting started with testing this out. (Note that the if condition for checking for "/r/front" is just because I had no idea what was causing the crash with that message and wanted to make sure it wasn't trying to use /r/front as an actual subreddit.)

    if data['subreddit'] != "/r/front":
        flair = get_flair(data['subreddit'][3:], data['author'])
        if flair != None:
            data['flair'] = flair['flair_text']
        else:``
            data['flair'] = ""

    else:
        data['flair'] = ""

The exception that it seems to be hitting is the one in main that catches SubredditNameErrors

@michael-lazar
Copy link
Owner Author

You're correct that the exception is getting caught where it shouldn't be.

content.py, line 361

content = cls(display_name, submissions, loader)                        
try:                                                                    
    content.get(0)                                                      
except:                                                                 
    # TODO: Trap specific errors                                        
    raise SubredditNameError(display_name) 

Try getting rid of this try-except block

content = cls(display_name, submissions, loader)
content.get(0)

and your error should propagate through.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants