GithubHelp home page GithubHelp logo

Comments (6)

tobywhughes avatar tobywhughes commented on May 28, 2024

I think I figured it out. Just with the way content.py checks /. Going to submit a pull request.

from rtv.

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

Thanks. I'll leave this open since I would rather get everything squared away with a single pull request.
I have some thoughts on switching subreddits in general...

It would be nice to have support for all of the following formats:

  • /r/python
  • /r/python/new
  • /r/python/rising
  • /r/python/controverisal
  • /r/python/top

with optional backslash at the end

  • /r/python/
  • /r/python/new/
  • ...

Using the same convention, we can link back to the front page. I have torn feelings about this one because /r/front already exists as a valid subreddit and using it as an alias feels kinda dirty.

  • /r/front
  • /r/front/new
  • /r/front/rising
  • ...

Support for multireddits also fits in nicely

  • /r/python+linux
  • /r/python+linux/new
  • ...

And of course we need to be able to handle bad input without crashing

  • /r//
  • /r/this/is/fake/
  • /r/python/banana

I think at this point it would be best to just refactor the whole from_name() function. I see two options moving forward.

  1. Stick to pure python using functions like split('/') and endswith('/new')
  2. shudder Regular Expressions

from rtv.

tobywhughes avatar tobywhughes commented on May 28, 2024

I don't think were going to have to use regex. I can see it by working in this way
1)Function to check for invalid backslashes
In this function it can:
1)Check for backslash at beginning. If there is, raise error
2)Check for backslash at end. If there is, remove it.
3)Now, after step two, there should only be one backslash if it is a valid input.
Here, we check if there is only one backslash. If not, raise error.

2)name, display_type = name.split('/')
3)Check display_type to see if they are valid. If not, raise error.
4)Deal with multireddits. Not sure what we are doing with it so I'll leave that out, but here seems like a logical place to fit it.
5)Check if subreddits are valid.
6)Get subreddits, with a different return depending on display_type.

I'm not sure about the front alias. I guess it could work, sort of like we already have it, but right before step 4, or 5 there can be a check if name = 'front' and have seperate return statements depending on what display_type equal like this:

    if name == 'front':
        if display_type == 'new':
            return cls('New', reddit.get_new(limit=None), loader)
        if display_type == 'top':
            return ...

from rtv.

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

I think this sounds like a good approach.
ย 
The display type should be optional, so we don't want to raise an error if there is no backslash. Something like this should work for step 2.

split_name = name.split('/')
if len(split_name) == 1:
    sub_name, display_type = split_name[0], 'hot'
elif len(split_name) == 2:
    sub_name, display_type = split_name
else:
    raise error

from rtv.

tobywhughes avatar tobywhughes commented on May 28, 2024

I instead just had display_type default to 'hot' so that it works like how reddit does it automatically. Just finished reworking it. About to submit it. Didn't deal with multireddits, but I still feel it should be merged since that is a slightly seperate issue than dealing with backslahes.

from rtv.

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

Marking this as closed. We may want to revisit once multireddits are implemented.

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.