diff --git a/rtv/content.py b/rtv/content.py index 45f88ae..6299da3 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -261,7 +261,7 @@ class SubredditContent(BaseContent): display_name += '/{}'.format(order) if name == 'me': - if not self.reddit.is_logged_in(): + if not reddit.is_logged_in(): raise AccountError else: submissions = reddit.user.get_submitted(sort=order) diff --git a/rtv/page.py b/rtv/page.py index e61c728..d55b511 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -244,11 +244,12 @@ class BasePage(object): return try: - self.reddit.login(username, password) + with self.loader(): + self.reddit.login(username, password) except praw.errors.InvalidUserPass: show_notification(self.stdscr, ['Invalid user/pass']) else: - show_notification(self.stdscr, ['Logged in']) + show_notification(self.stdscr, ['Welcome {}'.format(username)]) def logout(self): "Prompt to log out of the user's account." diff --git a/rtv/submission.py b/rtv/submission.py index 3712932..bf6a388 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -1,6 +1,7 @@ import curses import sys import time +import logging import praw.errors @@ -13,6 +14,7 @@ from .docs import COMMENT_FILE __all__ = ['SubmissionController', 'SubmissionPage'] +_logger = logging.getLogger(__name__) class SubmissionController(BaseController): character_map = {} @@ -87,7 +89,7 @@ class SubmissionPage(BasePage): """ if not self.reddit.is_logged_in(): - show_notification(self.stdscr, ['Not logged in']) + show_notification(self.stdscr, ['Login to post']) return data = self.content.get(self.nav.absolute_index) @@ -110,7 +112,7 @@ class SubmissionPage(BasePage): comment_text = open_editor(comment_info) curses.doupdate() if not comment_text: - curses.flash() + show_notification(self.stdscr, ['Comment canceled']) return try: @@ -119,9 +121,15 @@ class SubmissionPage(BasePage): else: data['object'].reply(comment_text) except praw.errors.APIException: - curses.flash() + message = ['Error: {}'.format(e.error_type), e.message] + show_notification(self.stdscr, message) + _logger.exception(e) + except requests.HTTPError as e: + show_notification(self.stdscr, ['Unexpected Error']) + _logger.exception(e) else: - time.sleep(2.0) + with self.loader(delay=0, message='Posting'): + time.sleep(2.0) self.refresh_content() def draw_item(self, win, data, inverted=False): diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 5eb3037..557974e 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -1,5 +1,7 @@ import curses import time +import logging + import requests import praw @@ -14,6 +16,8 @@ from .curses_helpers import (BULLET, UARROW, DARROW, GOLD, Color, __all__ = ['opened_links', 'SubredditController', 'SubredditPage'] +_logger = logging.getLogger(__name__) + # Used to keep track of browsing history across the current session opened_links = set() @@ -62,7 +66,7 @@ class SubredditPage(BasePage): "Open a prompt to search the given subreddit" name = name or self.content.name - prompt = 'Search:' + prompt = 'Search {}:'.format(name) query = self.prompt_input(prompt) if query is None: return @@ -110,7 +114,7 @@ class SubredditPage(BasePage): "Post a new submission to the given subreddit" if not self.reddit.is_logged_in(): - show_notification(self.stdscr, ['Not logged in']) + show_notification(self.stdscr, ['Login to post']) return # Strips the subreddit to just the name @@ -129,7 +133,7 @@ class SubredditPage(BasePage): # Validate the submission content if not submission_text: - curses.flash() + show_notification(self.stdscr, ['Post canceled']) return if '\n' not in submission_text: @@ -139,10 +143,16 @@ class SubredditPage(BasePage): try: title, content = submission_text.split('\n', 1) self.reddit.submit(sub, title, text=content) - except praw.errors.APIException: - curses.flash() + except praw.errors.APIException as e: + message = ['Error: {}'.format(e.error_type), e.message] + show_notification(self.stdscr, message) + _logger.exception(e) + except requests.HTTPError as e: + show_notification(self.stdscr, ['Unexpected Error']) + _logger.exception(e) else: - time.sleep(2.0) + with self.loader(delay=0, message='Posting'): + time.sleep(2.0) self.refresh_content() @staticmethod