Python 3.4 compatability.
This commit is contained in:
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
from contextlib import contextmanager
|
||||
|
||||
import praw
|
||||
import six
|
||||
|
||||
from errors import SubmissionURLError, SubredditNameError
|
||||
|
||||
@@ -11,7 +12,13 @@ def clean(unicode_string):
|
||||
Convert unicode string into ascii-safe characters.
|
||||
"""
|
||||
|
||||
return unicode_string.encode('ascii', 'replace').replace('\\', '')
|
||||
if six.PY2:
|
||||
ascii_string = unicode_string.encode('ascii', 'replace')
|
||||
else:
|
||||
ascii_string = unicode_string.encode().decode('ascii', 'replace')
|
||||
|
||||
ascii_string = ascii_string.replace('\\', '')
|
||||
return ascii_string
|
||||
|
||||
|
||||
def strip_subreddit_url(permalink):
|
||||
@@ -34,19 +41,19 @@ def humanize_timestamp(utc_timestamp, verbose=False):
|
||||
seconds = int(timedelta.total_seconds())
|
||||
if seconds < 60:
|
||||
return 'moments ago' if verbose else '0min'
|
||||
minutes = seconds / 60
|
||||
minutes = seconds // 60
|
||||
if minutes < 60:
|
||||
return ('%d minutes ago' % minutes) if verbose else ('%dmin' % minutes)
|
||||
hours = minutes / 60
|
||||
hours = minutes // 60
|
||||
if hours < 24:
|
||||
return ('%d hours ago' % hours) if verbose else ('%dhr' % hours)
|
||||
days = hours / 24
|
||||
days = hours // 24
|
||||
if days < 30:
|
||||
return ('%d days ago' % days) if verbose else ('%dday' % days)
|
||||
months = days / 30.4
|
||||
months = days // 30.4
|
||||
if months < 12:
|
||||
return ('%d months ago' % months) if verbose else ('%dmonth' % months)
|
||||
years = months / 12
|
||||
years = months // 12
|
||||
return ('%d years ago' % years) if verbose else ('%dyr' % years)
|
||||
|
||||
@contextmanager
|
||||
@@ -312,7 +319,7 @@ class SubredditContent(BaseContent):
|
||||
|
||||
try:
|
||||
with self._loader():
|
||||
submission = self._submissions.next()
|
||||
submission = next(self._submissions)
|
||||
except StopIteration:
|
||||
raise IndexError
|
||||
else:
|
||||
|
||||
@@ -40,13 +40,13 @@ def main():
|
||||
return
|
||||
|
||||
except ConnectionError:
|
||||
print 'Timeout: Could not connect to website'
|
||||
print('Timeout: Could not connect to website')
|
||||
|
||||
except SubmissionURLError as e:
|
||||
print 'Could not reach submission URL: {}'.format(e.url)
|
||||
print('Could not reach submission URL: {}'.format(e.url))
|
||||
|
||||
except SubredditNameError as e:
|
||||
print 'Could not reach subreddit: {}'.format(e.name)
|
||||
print('Could not reach subreddit: {}'.format(e.name))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -204,7 +204,7 @@ class BasePage(object):
|
||||
attribute |= attr
|
||||
|
||||
n_rows, _ = window.getmaxyx()
|
||||
for row in xrange(n_rows):
|
||||
for row in range(n_rows):
|
||||
window.chgat(row, 0, 1, attribute)
|
||||
|
||||
window.refresh()
|
||||
@@ -1,6 +1,8 @@
|
||||
import curses
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from content import SubmissionContent
|
||||
from page import BasePage
|
||||
from utils import LoadScreen, Color
|
||||
@@ -108,8 +110,14 @@ class SubmissionPage(BasePage):
|
||||
# Vertical line, unfortunately vline() doesn't support custom color so
|
||||
# we have to build it one chr at a time.
|
||||
attr = Color.get_level(data['level'])
|
||||
for y in xrange(n_rows):
|
||||
win.addch(y, 0, curses.ACS_VLINE, attr)
|
||||
for y in range(n_rows):
|
||||
|
||||
# Nobody pays attention to curses ;(
|
||||
# http://bugs.python.org/issue21088
|
||||
x = 0
|
||||
if (sys.version_info.major, sys.version_info.minor) == (3, 4):
|
||||
x, y = y, x
|
||||
win.addch(y, x, curses.ACS_VLINE, attr)
|
||||
|
||||
return attr | curses.ACS_VLINE
|
||||
|
||||
@@ -124,7 +132,7 @@ class SubmissionPage(BasePage):
|
||||
win.addnstr(text, n_cols - win.getyx()[1], attr)
|
||||
|
||||
attr = Color.get_level(data['level'])
|
||||
for y in xrange(n_rows):
|
||||
for y in range(n_rows):
|
||||
win.addch(y, 0, curses.ACS_VLINE, attr)
|
||||
|
||||
return attr | curses.ACS_VLINE
|
||||
|
||||
10
rtv/utils.py
10
rtv/utils.py
@@ -77,8 +77,8 @@ def display_message(stdscr, message):
|
||||
|
||||
message_len = len(message)
|
||||
n_rows, n_cols = stdscr.getmaxyx()
|
||||
s_row = (n_rows - 2) / 2
|
||||
s_col = (n_cols - message_len - 1) / 2
|
||||
s_row = (n_rows - 2) // 2
|
||||
s_col = (n_cols - message_len - 1) // 2
|
||||
window = stdscr.derwin(3, message_len+2, s_row, s_col)
|
||||
|
||||
window.erase()
|
||||
@@ -137,12 +137,12 @@ class LoadScreen(object):
|
||||
|
||||
message_len = len(message) + len(trail)
|
||||
n_rows, n_cols = self._stdscr.getmaxyx()
|
||||
s_row = (n_rows - 2) / 2
|
||||
s_col = (n_cols - message_len - 1) / 2
|
||||
s_row = (n_rows - 2) // 2
|
||||
s_col = (n_cols - message_len - 1) // 2
|
||||
window = self._stdscr.derwin(3, message_len+2, s_row, s_col)
|
||||
|
||||
while True:
|
||||
for i in xrange(len(trail)+1):
|
||||
for i in range(len(trail)+1):
|
||||
|
||||
if not self._is_running:
|
||||
window.clear()
|
||||
|
||||
6
setup.py
6
setup.py
@@ -1,4 +1,6 @@
|
||||
from setuptools import setup
|
||||
#python setup.py develop --user
|
||||
#python setup.py develop --user --uninstall
|
||||
|
||||
setup(
|
||||
name='rtv',
|
||||
@@ -10,8 +12,6 @@ setup(
|
||||
license='MIT',
|
||||
keywords='reddit terminal praw',
|
||||
packages=['rtv'],
|
||||
install_requires=['praw'],
|
||||
install_requires=['praw', 'six'],
|
||||
entry_points={'console_scripts': ['rtv=rtv:main']}
|
||||
)
|
||||
|
||||
#python setup.py develop --user
|
||||
Reference in New Issue
Block a user