Added -a for force_ascii, utf-8 by default
This commit is contained in:
7
__main__.py
Normal file
7
__main__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# Entry point for rtv module
|
||||
# Run by moving into the top level directory (the one with setup.py)
|
||||
# and typing "python -m rtv"
|
||||
|
||||
from rtv.main import main
|
||||
|
||||
main()
|
||||
@@ -8,12 +8,15 @@ import requests
|
||||
|
||||
from .errors import SubmissionURLError, SubredditNameError
|
||||
|
||||
is_utf8 = True
|
||||
|
||||
|
||||
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:
|
||||
@@ -21,6 +24,14 @@ def clean(unicode_string):
|
||||
|
||||
ascii_string = ascii_string.replace('\\', '')
|
||||
return ascii_string
|
||||
else:
|
||||
if six.PY2:
|
||||
utf8_string = unicode_string.encode('utf-8', 'replace')
|
||||
else:
|
||||
utf8_string = unicode_string.encode().decode('utf-8', 'replace')
|
||||
|
||||
utf8_string = utf8_string.replace('\\', '')
|
||||
return utf8_string
|
||||
|
||||
|
||||
def split_text(big_text, width):
|
||||
|
||||
@@ -8,7 +8,10 @@ from .errors import SubmissionURLError, SubredditNameError
|
||||
from .utils import curses_session, load_config, HELP
|
||||
from .subreddit import SubredditPage
|
||||
from .submission import SubmissionPage
|
||||
import locale
|
||||
import rtv.content
|
||||
|
||||
is_utf8 = True # if -a is set then this is set to false
|
||||
|
||||
DESCRIPTION = """
|
||||
Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a
|
||||
@@ -34,6 +37,8 @@ def main():
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('-s', dest='subreddit', help='subreddit name')
|
||||
parser.add_argument('-l', dest='link', help='full link to a submission')
|
||||
parser.add_argument('-a', dest='force_ascii',
|
||||
help='forces ascii (disables unicode)', action='store_true')
|
||||
|
||||
group = parser.add_argument_group(
|
||||
'authentication (optional)',
|
||||
@@ -54,6 +59,10 @@ def main():
|
||||
if args.subreddit is None:
|
||||
args.subreddit = 'front'
|
||||
|
||||
if args.force_ascii:
|
||||
rtv.content.is_utf8 = False
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
try:
|
||||
reddit = praw.Reddit(user_agent='desktop:https://github.com/michael-lazar/rtv:(by /u/civilization_phaze_3)')
|
||||
reddit.config.decode_html_entities = True
|
||||
|
||||
Reference in New Issue
Block a user