Switched to relative imports for python3.

This commit is contained in:
Michael Lazar
2015-02-03 22:09:19 -08:00
parent cafc08dafa
commit 31529a9770
8 changed files with 21 additions and 22 deletions

View File

@@ -1 +0,0 @@
from main import main

View File

@@ -5,7 +5,7 @@ from contextlib import contextmanager
import praw
import six
from errors import SubmissionURLError, SubredditNameError
from .errors import SubmissionURLError, SubredditNameError
def clean(unicode_string):
"""
@@ -69,7 +69,7 @@ class BaseContent(object):
while True:
try:
yield self.get(index, n_cols)
yield self.get(index, n_cols=n_cols)
except IndexError:
break
index += step
@@ -231,7 +231,7 @@ class SubmissionContent(BaseContent):
return data
def toggle(self, index):
def toggle(self, index, n_cols=70):
"""
Toggle the state of the object at the given index.
@@ -244,7 +244,7 @@ class SubmissionContent(BaseContent):
if data['type'] == 'Comment':
cache = [data]
count = 1
for d in self.iterate(index+1, 1):
for d in self.iterate(index+1, 1, n_cols):
if d['level'] <= data['level']:
break
@@ -256,7 +256,7 @@ class SubmissionContent(BaseContent):
comment['cache'] = cache
comment['count'] = count
comment['level'] = data['level']
comment['body'] = 'Hidden [{}]'.format(count)
comment['body'] = 'Hidden'.format(count)
self._comment_data[index:index+len(cache)] = [comment]
elif data['type'] == 'HiddenComment':

View File

@@ -1,53 +0,0 @@
import argparse
import praw
from requests.exceptions import ConnectionError
from errors import SubmissionURLError, SubredditNameError
from utils import curses_session
from subreddit import SubredditPage
from submission import SubmissionPage
parser = argparse.ArgumentParser(description='Reddit Terminal Viewer')
parser.add_argument('-s', dest='subreddit', default='front', help='subreddit name')
parser.add_argument('-l', dest='link', help='full link to a submission')
group = parser.add_argument_group('authentication (optional)')
group.add_argument('-u', dest='username', help='reddit username')
group.add_argument('-p', dest='password', help='reddit password')
def main():
args = parser.parse_args()
try:
reddit = praw.Reddit(user_agent='reddit terminal viewer v0.0')
reddit.config.decode_html_entities = True
if args.username and args.password:
reddit.login(args.username, args.password)
with curses_session() as stdscr:
if args.link:
# Go directly to submission
page = SubmissionPage(stdscr, reddit, url=args.link)
page.loop()
page = SubredditPage(stdscr, reddit, args.subreddit)
page.loop()
except KeyboardInterrupt:
return
except ConnectionError:
print('Timeout: Could not connect to website')
except SubmissionURLError as e:
print('Could not reach submission URL: {}'.format(e.url))
except SubredditNameError as e:
print('Could not reach subreddit: {}'.format(e.name))
if __name__ == '__main__':
main()

View File

@@ -1,6 +1,6 @@
import curses
from utils import Color
from .utils import Color
class Navigator(object):
"""

View File

@@ -3,9 +3,9 @@ import sys
import six
from content import SubmissionContent
from page import BasePage
from utils import LoadScreen, Color
from .content import SubmissionContent
from .page import BasePage
from .utils import LoadScreen, Color
class SubmissionPage(BasePage):

View File

@@ -1,11 +1,11 @@
import curses
import sys
from errors import SubredditNameError
from page import BasePage
from submission import SubmissionPage
from content import SubredditContent
from utils import LoadScreen, text_input, display_message, Color
from .errors import SubredditNameError
from .page import BasePage
from .submission import SubmissionPage
from .content import SubredditContent
from .utils import LoadScreen, text_input, display_message, Color
class SubredditPage(BasePage):

View File

@@ -5,7 +5,7 @@ import threading
from curses import textpad
from contextlib import contextmanager
from errors import EscapePressed
from .errors import EscapePressed
class Color(object):