Giter Site home page Giter Site logo

Support for flairs about rtv HOT 9 CLOSED

michael-lazar avatar michael-lazar commented on May 18, 2024
Support for flairs

from rtv.

Comments (9)

tobywhughes avatar tobywhughes commented on May 18, 2024

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.

from rtv.

shawnhind avatar shawnhind commented on May 18, 2024

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

from rtv.

shawnhind avatar shawnhind commented on May 18, 2024

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?

from rtv.

michael-lazar avatar michael-lazar commented on May 18, 2024

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.

from rtv.

shawnhind avatar shawnhind commented on May 18, 2024

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 [email protected] 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.

from rtv.

michael-lazar avatar michael-lazar commented on May 18, 2024

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.

from rtv.

shawnhind avatar shawnhind commented on May 18, 2024

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.

from rtv.

shawnhind avatar shawnhind commented on May 18, 2024

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

from rtv.

michael-lazar avatar michael-lazar commented on May 18, 2024

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.

from rtv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.