Added logic, still need to test.

This commit is contained in:
Michael Lazar
2016-06-23 18:30:58 -07:00
parent b64ee6fa94
commit 33257ac3d1
5 changed files with 99 additions and 63 deletions

View File

@@ -10,6 +10,7 @@ from .page import Page, PageController, logged_in
from .objects import Navigator, Color, Command
from .submission import SubmissionPage
from .subscription import SubscriptionPage
from .exceptions import TemporaryFileError
class SubredditController(PageController):
@@ -118,31 +119,31 @@ class SubredditPage(Page):
return
submission_info = docs.SUBMISSION_FILE.format(name=name)
text = self.term.open_editor(submission_info)
if not text or '\n' not in text:
self.term.show_notification('Canceled')
return
with self.term.open_editor(submission_info) as text:
if not text or '\n' not in text:
self.term.show_notification('Canceled')
return
title, content = text.split('\n', 1)
with self.term.loader('Posting', delay=0):
submission = self.reddit.submit(name, title, text=content,
raise_captcha_exception=True)
# Give reddit time to process the submission
time.sleep(2.0)
if self.term.loader.exception:
return
title, content = text.split('\n', 1)
with self.term.loader('Posting', delay=0):
submission = self.reddit.submit(name, title, text=content,
raise_captcha_exception=True)
# Give reddit time to process the submission
time.sleep(2.0)
if self.term.loader.exception:
raise TemporaryFileError()
# Open the newly created post
with self.term.loader('Loading submission'):
page = SubmissionPage(
self.reddit, self.term, self.config, self.oauth,
submission=submission)
if self.term.loader.exception:
return
# Open the newly created post
with self.term.loader('Loading submission'):
page = SubmissionPage(
self.reddit, self.term, self.config, self.oauth,
submission=submission)
if self.term.loader.exception:
return
page.loop()
page.loop()
self.refresh_content()
self.refresh_content()
@SubredditController.register(Command('SUBREDDIT_OPEN_SUBSCRIPTIONS'))
@logged_in