Merge pull request #33 from ragreener1/master

Fixed issue #23
This commit is contained in:
michael-lazar
2015-03-10 15:47:24 -07:00
2 changed files with 30 additions and 11 deletions

View File

@@ -8,19 +8,30 @@ import requests
from .errors import SubmissionURLError, SubredditNameError from .errors import SubmissionURLError, SubredditNameError
is_utf8 = True
def clean(unicode_string): def clean(unicode_string):
""" """
Convert unicode string into ascii-safe characters. Checks if -a was given, if it was it
converts unicode string into ascii-safe characters.
""" """
if not is_utf8:
if six.PY2:
ascii_string = unicode_string.encode('ascii', 'replace')
else:
ascii_string = unicode_string.encode().decode('ascii', 'replace')
if six.PY2: ascii_string = ascii_string.replace('\\', '')
ascii_string = unicode_string.encode('ascii', 'replace') return ascii_string
else: else:
ascii_string = unicode_string.encode().decode('ascii', 'replace') if six.PY2:
utf8_string = unicode_string.encode('utf-8', 'replace')
else:
utf8_string = unicode_string.encode().decode('utf-8', 'replace')
ascii_string = ascii_string.replace('\\', '') utf8_string = utf8_string.replace('\\', '')
return ascii_string return utf8_string
def split_text(big_text, width): def split_text(big_text, width):

View File

@@ -7,6 +7,8 @@ from .errors import SubmissionURLError, SubredditNameError
from .utils import curses_session, load_config, HELP from .utils import curses_session, load_config, HELP
from .subreddit import SubredditPage from .subreddit import SubredditPage
from .submission import SubmissionPage from .submission import SubmissionPage
import locale
import rtv.content
# Debugging # Debugging
# import logging # import logging
@@ -21,9 +23,9 @@ EPILOG = """
Controls Controls
----- -----
RTV currently supports browsing both subreddits and individual submissions. RTV currently supports browsing both subreddits and individual submissions.
In each mode the controls are slightly different. In subreddit mode you can In each mode the controls are slightly different. In subreddit mode you can
browse through the top submissions on either the front page or a specific browse through the top submissions on either the front page or a specific
subreddit. In submission mode you can view the self text for a submission and subreddit. In submission mode you can view the self text for a submission and
browse comments. browse comments.
""" """
@@ -36,9 +38,11 @@ def main():
formatter_class=argparse.RawDescriptionHelpFormatter) formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-s', dest='subreddit', help='subreddit name') parser.add_argument('-s', dest='subreddit', help='subreddit name')
parser.add_argument('-l', dest='link', help='full link to a submission') parser.add_argument('-l', dest='link', help='full link to a submission')
parser.add_argument('--force-ascii', dest='force_ascii',
help='forces ascii (disables unicode)', action='store_true')
group = parser.add_argument_group( group = parser.add_argument_group(
'authentication (optional)', 'authentication (optional)',
'Authenticating allows you to view your customized front page. ' 'Authenticating allows you to view your customized front page. '
'If only the username is given, the password will be prompted ' 'If only the username is given, the password will be prompted '
'securely.') 'securely.')
@@ -56,6 +60,10 @@ def main():
if args.subreddit is None: if args.subreddit is None:
args.subreddit = 'front' args.subreddit = 'front'
if args.force_ascii:
rtv.content.is_utf8 = False
locale.setlocale(locale.LC_ALL, '')
try: try:
reddit = praw.Reddit(user_agent='desktop:https://github.com/michael-lazar/rtv:(by /u/civilization_phaze_3)') reddit = praw.Reddit(user_agent='desktop:https://github.com/michael-lazar/rtv:(by /u/civilization_phaze_3)')
reddit.config.decode_html_entities = True reddit.config.decode_html_entities = True
@@ -73,7 +81,7 @@ def main():
page.loop() page.loop()
except InvalidUserPass: except InvalidUserPass:
print('Invalid password for username: {}'.format(args.username)) print('Invalid password for username: {}'.format(args.username))
except KeyboardInterrupt: except KeyboardInterrupt:
return return