1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

switch to veryprettytable + colors

This commit is contained in:
Viktor Stanchev 2015-09-20 00:07:23 -07:00
parent 6adf0581dc
commit 1e7da45710
3 changed files with 15 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import shutil
from io import BytesIO from io import BytesIO
import colorama import colorama
import prettytable import veryprettytable
import pirate.data import pirate.data
@ -37,12 +37,12 @@ def print(*args, **kwargs):
# TODO: extract the name from the search results instead of from the magnet link when possible # TODO: extract the name from the search results instead of from the magnet link when possible
def search_results(results, local=None): def search_results(results, local=None):
columns = shutil.get_terminal_size((80, 20)).columns columns = shutil.get_terminal_size((80, 20)).columns
cur_color = 'zebra_0' even = True
if local: if local:
table = prettytable.PrettyTable(['LINK', 'NAME']) table = veryprettytable.VeryPrettyTable(['LINK', 'NAME'])
else: else:
table = prettytable.PrettyTable(['LINK', 'SEED', 'LEECH', 'RATIO', 'SIZE', '', 'UPLOAD', 'NAME']) table = veryprettytable.VeryPrettyTable(['LINK', 'SEED', 'LEECH', 'RATIO', 'SIZE', '', 'UPLOAD', 'NAME'])
table.align['NAME'] = 'l' table.align['NAME'] = 'l'
table.align['SEED'] = 'r' table.align['SEED'] = 'r'
table.align['LEECH'] = 'r' table.align['LEECH'] = 'r'
@ -55,8 +55,6 @@ def search_results(results, local=None):
table.padding_width = 1 table.padding_width = 1
for n, result in enumerate(results): for n, result in enumerate(results):
# Alternate between colors
cur_color = 'zebra_0' if cur_color == 'zebra_1' else 'zebra_1'
name = re.search(r'dn=([^\&]*)', result['magnet']) name = re.search(r'dn=([^\&]*)', result['magnet'])
torrent_name = parse.unquote_plus(name.group(1)) torrent_name = parse.unquote_plus(name.group(1))
@ -80,10 +78,16 @@ def search_results(results, local=None):
except ZeroDivisionError: except ZeroDivisionError:
ratio = float('inf') ratio = float('inf')
content = [n, no_seeders, no_leechers, '{0:.1f}'.format(ratio), content = [n, no_seeders, no_leechers, '{:.1f}'.format(ratio),
'{0:.1f}'.format(size), unit, date, torrent_name[:columns - 53]] '{:.1f}'.format(size), unit, date, torrent_name[:columns - 53]]
table.add_row(content) if even:
table.add_row(content)
else:
table.add_row(content, fore_color='blue')
# Alternate between colors
even = not even
print(table) print(table)

View File

@ -13,7 +13,7 @@ setup(name='pirate-get',
entry_points={ entry_points={
'console_scripts': ['pirate-get = pirate.pirate:main'] 'console_scripts': ['pirate-get = pirate.pirate:main']
}, },
install_requires=['colorama>=0.3.3', 'pyquery>=1.2.9', 'PrettyTable>=0.7.2'], install_requires=['colorama>=0.3.3', 'pyquery>=1.2.9', 'veryprettytable>=0.8.1'],
keywords=['torrent', 'magnet', 'download', 'tpb', 'client'], keywords=['torrent', 'magnet', 'download', 'tpb', 'client'],
classifiers=[ classifiers=[
'Topic :: Utilities', 'Topic :: Utilities',

View File

@ -29,7 +29,7 @@ class TestPrint(unittest.TestCase):
add_row = MagicMock() add_row = MagicMock()
align = {} align = {}
mock = MockTable() mock = MockTable()
with patch('prettytable.PrettyTable', return_value=mock) as prettytable: with patch('veryprettytable.VeryPrettyTable', return_value=mock) as prettytable:
results = [{ results = [{
'magnet': 'dn=name', 'magnet': 'dn=name',
'Name': 'name', 'Name': 'name',