Comments (6)
I think I figured it out. Just with the way content.py checks /. Going to submit a pull request.
from rtv.
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.
- Stick to pure python using functions like split('/') and endswith('/new')
- shudder Regular Expressions
from rtv.
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.
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.
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.
Marking this as closed. We may want to revisit once multireddits are implemented.
from rtv.
Related Issues (20)
- add Twitch mime parser HOT 5
- Crash when hitting G on empty thread HOT 1
- RTV development is shutting down HOT 30
- Offering to help with the project HOT 1
- ConnectionError upon first launch
- no confirmation on exit HOT 1
- Program exited with status 127 HOT 1
- When you set $RTV_BROWSER variable to a program with options like "mybrowser -u" it basicly doesn't work HOT 1
- [1.2.7] Where is the configuration option to toggle whether to open web browser links in a new tab or a new window?
- Not being able to view remote image url via iTerm2's imgcat HOT 6
- How do I change it that rtv uses leafpad instead of nano as its default text editor?
- Save option for posts.
- Option to edit a posted comment.
- Where does rtv store the credentials or session/cookie file so I could just take a rtv install to another OS/new install and donโt have to reopen Firefox for allowing the app access?
- Version 1.27.0_1 (from brew) crashed when opening url HOT 5
- Fix incase mpv is not opening anymore
- When pressing < o > key on a reddit post rtv crashes, "Can't pickle local object" HOT 1
- Crash while trying to sign in HOT 1
- Crash while trying to open a submission link HOT 2
- Archiving Github Repository
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtv.