Merge branch 'master' of https://github.com/michael-lazar/rtv
This commit is contained in:
@@ -91,14 +91,12 @@ In submission mode you can view the self text for a submission and browse commen
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
RTV will read a configuration file located at **~/.rtv**.
|
||||
RTV will read a configuration file located at ``$XDG_CONFIG_HOME/rtv/rtv.cfg`` or ``~/.config/rtv/rtv.cfg`` if ``$XDG_CONFIG_HOME`` is not set.
|
||||
This can be used to avoid having to re-enter login credentials every time the program is launched.
|
||||
Each line in the file will replace the corresponding default argument in the launch script.
|
||||
|
||||
Example config:
|
||||
|
||||
**~/.rtv**
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[rtv]
|
||||
|
||||
@@ -26,9 +26,20 @@ def load_config():
|
||||
saved settings for things like the username and password.
|
||||
"""
|
||||
|
||||
config_path = os.path.join(os.path.expanduser('~'), '.rtv')
|
||||
config = configparser.ConfigParser()
|
||||
|
||||
HOME = os.path.expanduser('~')
|
||||
XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config'))
|
||||
config_paths = [
|
||||
os.path.join(XDG_CONFIG_HOME, 'rtv', 'rtv.cfg'),
|
||||
os.path.join(HOME, '.rtv')
|
||||
]
|
||||
|
||||
# read only the first existing config file
|
||||
for config_path in config_paths:
|
||||
if os.path.exists(config_path):
|
||||
config.read(config_path)
|
||||
break
|
||||
|
||||
defaults = {}
|
||||
if config.has_section('rtv'):
|
||||
|
||||
@@ -79,6 +79,7 @@ class BaseContent(object):
|
||||
flair = comment.author_flair_text
|
||||
data['flair'] = (flair if flair else '')
|
||||
data['likes'] = comment.likes
|
||||
data['gold'] = comment.gilded > 0
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ ESCAPE = 27
|
||||
UARROW = u'\u25b2'.encode('utf-8')
|
||||
DARROW = u'\u25bc'.encode('utf-8')
|
||||
BULLET = u'\u2022'.encode('utf-8')
|
||||
GOLD = u'\u272A'.encode('utf-8')
|
||||
|
||||
|
||||
def show_notification(stdscr, message):
|
||||
|
||||
10
rtv/docs.py
10
rtv/docs.py
@@ -52,3 +52,13 @@ COMMENT_FILE = """
|
||||
# Replying to {author}'s {type}
|
||||
{content}
|
||||
"""
|
||||
|
||||
SUBMISSION_FILE = """
|
||||
# Please enter your submission. Lines starting with '#' will be ignored,
|
||||
# and an empty field aborts the submission.
|
||||
#
|
||||
# The first line will be interpreted as the title
|
||||
# Following lines will be interpreted as the content
|
||||
#
|
||||
# Posting to /r/{name}
|
||||
"""
|
||||
|
||||
@@ -7,7 +7,7 @@ import praw.errors
|
||||
from .content import SubmissionContent
|
||||
from .page import BasePage, Navigator, BaseController
|
||||
from .helpers import clean, open_browser, open_editor
|
||||
from .curses_helpers import (BULLET, UARROW, DARROW, Color, LoadScreen,
|
||||
from .curses_helpers import (BULLET, UARROW, DARROW, GOLD, Color, LoadScreen,
|
||||
show_notification, text_input)
|
||||
from .docs import COMMENT_FILE
|
||||
|
||||
@@ -157,9 +157,13 @@ class SubmissionPage(BasePage):
|
||||
text, attr = DARROW, (curses.A_BOLD | Color.RED)
|
||||
win.addnstr(text, n_cols - win.getyx()[1], attr)
|
||||
|
||||
text = clean(u' {score} {created}'.format(**data))
|
||||
text = clean(u' {score} {created} '.format(**data))
|
||||
win.addnstr(text, n_cols - win.getyx()[1])
|
||||
|
||||
if data['gold']:
|
||||
text, attr = GOLD, (curses.A_BOLD | Color.YELLOW)
|
||||
win.addnstr(text, n_cols - win.getyx()[1], attr)
|
||||
|
||||
n_body = len(data['split_body'])
|
||||
for row, text in enumerate(data['split_body'], start=offset + 1):
|
||||
if row in valid_rows:
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import curses
|
||||
|
||||
import time
|
||||
import requests
|
||||
import praw
|
||||
|
||||
from .exceptions import SubredditError
|
||||
from .page import BasePage, Navigator, BaseController
|
||||
from .submission import SubmissionPage
|
||||
from .content import SubredditContent
|
||||
from .helpers import clean, open_browser
|
||||
from .helpers import clean, open_browser, open_editor
|
||||
from .docs import SUBMISSION_FILE
|
||||
from .curses_helpers import (BULLET, UARROW, DARROW, Color, LoadScreen,
|
||||
show_notification)
|
||||
|
||||
@@ -94,6 +96,44 @@ class SubredditPage(BasePage):
|
||||
global opened_links
|
||||
opened_links.add(url)
|
||||
|
||||
@SubredditController.register('p')
|
||||
def post_submission(self):
|
||||
# Abort if user isn't logged in
|
||||
if not self.reddit.is_logged_in():
|
||||
show_notification(self.stdscr, ['Login to reply'])
|
||||
return
|
||||
|
||||
subreddit = self.reddit.get_subreddit(self.content.name)
|
||||
|
||||
# Make sure it is a valid subreddit for submission
|
||||
# Strips the subreddit to just the name
|
||||
sub = str(subreddit).split('/')[2]
|
||||
if '+' in sub or sub == 'all' or sub == 'front':
|
||||
message = 'Can\'t post to /r/{0}'.format(sub)
|
||||
show_notification(self.stdscr, [message])
|
||||
return
|
||||
|
||||
# Open the submission window
|
||||
submission_info = SUBMISSION_FILE.format(name=sub)
|
||||
curses.endwin()
|
||||
submission_text = open_editor(submission_info)
|
||||
curses.doupdate()
|
||||
|
||||
# Abort if there is no content
|
||||
if not submission_text:
|
||||
curses.flash()
|
||||
return
|
||||
try:
|
||||
title, content = submission_text.split('\n', 1)
|
||||
self.reddit.submit(sub, title, text=content)
|
||||
except praw.errors.APIException as e:
|
||||
show_notification(self.stdscr, [e.message])
|
||||
except ValueError:
|
||||
show_notification(self.stdscr, ['No post content! Post aborted.'])
|
||||
else:
|
||||
time.sleep(0.5)
|
||||
self.refresh_content()
|
||||
|
||||
@staticmethod
|
||||
def draw_item(win, data, inverted=False):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user