diff --git a/README.rst b/README.rst index e5d8c02..020a3b9 100644 --- a/README.rst +++ b/README.rst @@ -71,6 +71,7 @@ In subreddit mode you can browse through the top submissions on either the front :``►`` or ``l``: View comments for the selected submission :``/``: Open a prompt to switch subreddits :``f``: Open a prompt to search the current subreddit +:``p``: Post a Submission to the current subreddit The ``/`` prompt accepts subreddits in the following formats @@ -78,6 +79,7 @@ The ``/`` prompt accepts subreddits in the following formats * ``/r/python/new`` * ``/r/python+linux`` supports multireddits * ``/r/front`` will redirect to the front page +* ``/r/me`` will show you your submissions on all subs **Submission Mode** diff --git a/rtv/content.py b/rtv/content.py index de82269..a42fe23 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -304,6 +304,18 @@ class SubredditContent(BaseContent): return cls(display_name, submissions, loader) + @classmethod + def from_redditor(cls, reddit, loader, order='new'): + submissions = reddit.user.get_submitted(sort=order) + display_name = '/r/me' + content = cls(display_name, submissions, loader) + try: + content.get(0) + except (praw.errors.APIException, requests.HTTPError, + praw.errors.RedirectException): + raise SubredditError(display_name) + return content + def get(self, index, n_cols=70): """ Grab the `i`th submission, with the title field formatted to fit inside diff --git a/rtv/docs.py b/rtv/docs.py index 430af2a..33002fe 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -38,6 +38,7 @@ Subreddit Mode `RIGHT` or `l` : View comments for the selected submission `/` : Open a prompt to switch subreddits `f` : Open a prompt to search the current subreddit + `p` : Post a Submission to the current subreddit Submission Mode `LEFT` or `h` : Return to subreddit mode diff --git a/rtv/submission.py b/rtv/submission.py index 35089fc..db32633 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -31,8 +31,8 @@ class SubmissionPage(BasePage): else: raise ValueError('Must specify url or submission') - super(SubmissionPage, self).__init__(stdscr, reddit, content, - page_index=-1) + super(SubmissionPage, self).__init__(stdscr, reddit, + content, page_index=-1) def loop(self): self.active = True diff --git a/rtv/subreddit.py b/rtv/subreddit.py index a5ec0e8..14580e9 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -41,7 +41,9 @@ class SubredditPage(BasePage): @SubredditController.register(curses.KEY_F5, 'r') def refresh_content(self, name=None): name = name or self.content.name - + if name == 'me' or name == '/r/me': + self.redditor_profile() + return try: self.content = SubredditContent.from_name( self.reddit, name, self.loader) @@ -74,6 +76,16 @@ class SubredditPage(BasePage): if name is not None: self.refresh_content(name=name) + def redditor_profile(self): + if self.reddit.is_logged_in(): + try: + self.content = SubredditContent.from_redditor( + self.reddit, self.loader) + except requests.HTTPError: + show_notification(self.stdscr, ['Could not reach subreddit']) + else: + show_notification(self.stdscr, ['Log in to view your submissions']) + @SubredditController.register(curses.KEY_RIGHT, 'l') def open_submission(self): "Select the current submission to view posts"