properly strip subreddit name and post submission
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import curses
|
import curses
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
import praw
|
||||||
|
|
||||||
from .exceptions import SubredditError
|
from .exceptions import SubredditError
|
||||||
from .page import BasePage, Navigator, BaseController
|
from .page import BasePage, Navigator, BaseController
|
||||||
@@ -102,6 +103,10 @@ class SubredditPage(BasePage):
|
|||||||
show_notification(self.stdscr, ['Can\'t post to a multireddit'])
|
show_notification(self.stdscr, ['Can\'t post to a multireddit'])
|
||||||
return
|
return
|
||||||
|
|
||||||
|
name = name.strip(' /') # Strip leading and trailing backslashes
|
||||||
|
if name.startswith('r/'):
|
||||||
|
name = name[2:]
|
||||||
|
|
||||||
# Open the submission window
|
# Open the submission window
|
||||||
submission_info = SUBMISSION_FILE.format(name=name)
|
submission_info = SUBMISSION_FILE.format(name=name)
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
@@ -114,7 +119,7 @@ class SubredditPage(BasePage):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
title, content = submission_text.split('\n', 1)
|
title, content = submission_text.split('\n', 1)
|
||||||
show_notification(self.stdscr, [title])
|
self.reddit.submit(name, title, text=content)
|
||||||
except praw.errors.APIException as e:
|
except praw.errors.APIException as e:
|
||||||
show_notification(self.stdscr, [e.message])
|
show_notification(self.stdscr, [e.message])
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user