Added error checking, still need to test.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from .__version__ import __version__
|
from .__version__ import __version__
|
||||||
|
|
||||||
__all__ = ['AGENT', 'SUMMARY', 'AUTH', 'CONTROLS', 'HELP', 'COMMENT_FILE',
|
__all__ = ['AGENT', 'SUMMARY', 'AUTH', 'CONTROLS', 'HELP', 'COMMENT_FILE',
|
||||||
'SUBMISSION_FILE']
|
'SUBMISSION_FILE', 'COMMENT_EDIT_FILE']
|
||||||
|
|
||||||
AGENT = """\
|
AGENT = """\
|
||||||
desktop:https://github.com/michael-lazar/rtv:{} (by /u/civilization_phaze_3)\
|
desktop:https://github.com/michael-lazar/rtv:{} (by /u/civilization_phaze_3)\
|
||||||
@@ -71,5 +71,5 @@ SUBMISSION_FILE = """{content}
|
|||||||
# The first line will be interpreted as the title
|
# The first line will be interpreted as the title
|
||||||
# The following lines will be interpreted as the content
|
# The following lines will be interpreted as the content
|
||||||
#
|
#
|
||||||
# Posting to /r/{name}
|
# Posting to {name}
|
||||||
"""
|
"""
|
||||||
51
rtv/page.py
51
rtv/page.py
@@ -2,15 +2,17 @@ import curses
|
|||||||
import time
|
import time
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
import praw.errors
|
import praw.errors
|
||||||
|
|
||||||
from .helpers import clean, open_editor
|
from .helpers import clean, open_editor
|
||||||
from .curses_helpers import Color, show_notification, show_help, text_input
|
from .curses_helpers import Color, show_notification, show_help, text_input
|
||||||
from .docs import AGENT, COMMENT_EDIT_FILE, SUBMISSION_FILE
|
from .docs import COMMENT_EDIT_FILE, SUBMISSION_FILE
|
||||||
|
|
||||||
__all__ = ['Navigator']
|
__all__ = ['Navigator', 'BaseController', 'BasePage']
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Navigator(object):
|
class Navigator(object):
|
||||||
"""
|
"""
|
||||||
@@ -261,26 +263,29 @@ class BasePage(object):
|
|||||||
show_notification(self.stdscr, ['Login to delete'])
|
show_notification(self.stdscr, ['Login to delete'])
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
data = self.content.get(self.nav.absolute_index)
|
||||||
data = self.content.get(self.nav.absolute_index)
|
if data.get('author') != self.reddit.user.name:
|
||||||
if data['author'] != self.reddit.user.name:
|
curses.flash()
|
||||||
return
|
|
||||||
except KeyError:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
prompt = 'Are you sure you want to delete this? (y/n):'
|
prompt = 'Are you sure you want to delete this? (y/n):'
|
||||||
char = self.prompt_input(prompt)
|
char = self.prompt_input(prompt)
|
||||||
if char != 'y':
|
if char != 'y':
|
||||||
show_notification(self.stdscr, ['Delete cancelled'])
|
show_notification(self.stdscr, ['Delete canceled'])
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data['object'].delete()
|
data['object'].delete()
|
||||||
show_notification(self.stdscr, ['Deleted'])
|
|
||||||
except praw.errors.APIException as e:
|
except praw.errors.APIException as e:
|
||||||
show_notification(self.stdscr, [e.message])
|
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:
|
else:
|
||||||
time.sleep(0.5)
|
with self.loader(delay=0, message='Deleting'):
|
||||||
|
time.sleep(2.0)
|
||||||
self.refresh_content()
|
self.refresh_content()
|
||||||
|
|
||||||
@BaseController.register('e')
|
@BaseController.register('e')
|
||||||
@@ -292,20 +297,15 @@ class BasePage(object):
|
|||||||
show_notification(self.stdscr, ['Login to edit'])
|
show_notification(self.stdscr, ['Login to edit'])
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
data = self.content.get(self.nav.absolute_index)
|
||||||
data = self.content.get(self.nav.absolute_index)
|
if data.get('author') != self.reddit.user.name:
|
||||||
if data['author'] != self.reddit.user.name:
|
curses.flash()
|
||||||
return
|
|
||||||
except KeyError:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if data['type'] == 'Submission':
|
if data['type'] == 'Submission':
|
||||||
subreddit = self.reddit.get_subreddit(self.content.name)
|
subreddit = self.reddit.get_subreddit(self.content.name)
|
||||||
sub = str(subreddit).split('/')[2]
|
|
||||||
sub_file = SUBMISSION_FILE
|
|
||||||
content = data['text']
|
content = data['text']
|
||||||
info = sub_file.format(content=content, name=sub)
|
info = SUBMISSION_FILE.format(content=content, name=subreddit)
|
||||||
|
|
||||||
elif data['type'] == 'Comment':
|
elif data['type'] == 'Comment':
|
||||||
content = data['body']
|
content = data['body']
|
||||||
info = COMMENT_EDIT_FILE.format(content=content)
|
info = COMMENT_EDIT_FILE.format(content=content)
|
||||||
@@ -318,14 +318,21 @@ class BasePage(object):
|
|||||||
curses.doupdate()
|
curses.doupdate()
|
||||||
|
|
||||||
if text == content:
|
if text == content:
|
||||||
|
show_notification(self.stdscr, ['Edit canceled'])
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data['object'].edit(text)
|
data['object'].edit(text)
|
||||||
except praw.errors.APIException as e:
|
except praw.errors.APIException as e:
|
||||||
show_notification(self.stdscr, [e.message])
|
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:
|
else:
|
||||||
time.sleep(0.5)
|
with self.loader(delay=0, message='Posting'):
|
||||||
|
time.sleep(2.0)
|
||||||
self.refresh_content()
|
self.refresh_content()
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class SubredditPage(BasePage):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Open the submission window
|
# Open the submission window
|
||||||
submission_info = SUBMISSION_FILE.format(name=sub, content='')
|
submission_info = SUBMISSION_FILE.format(name=subreddit, content='')
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
submission_text = open_editor(submission_info)
|
submission_text = open_editor(submission_info)
|
||||||
curses.doupdate()
|
curses.doupdate()
|
||||||
|
|||||||
Reference in New Issue
Block a user