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

Better formatting

This commit is contained in:
Rnhmjoj 2014-12-04 19:29:10 +01:00
parent 23211e5a91
commit 1c14b61ee6

View File

@ -285,9 +285,10 @@ def print_search_results(mags, sizes, uploaded):
columns = int(os.popen('stty size', 'r').read().split()[1]) - 55 columns = int(os.popen('stty size', 'r').read().split()[1]) - 55
cur_color = 'zebra_0' cur_color = 'zebra_0'
print("%5s %6s %6s %-5s %-11s %-11s %-*s" \ print('{:>4} {:>5} {:>5} {:>5} {:9} {:11} {:{length}}'.format(
% ( "LINK", "SEED", "LEECH", "RATIO", "SIZE", "UPLOAD", columns, "NAME"), 'LINK', 'SEED', 'LEECH', 'RATIO',
color="header") 'SIZE', 'UPLOAD', 'NAME', length=columns),
color='header')
for m, magnet in enumerate(mags): for m, magnet in enumerate(mags):
no_seeders = int(magnet[1]) no_seeders = int(magnet[1])
@ -298,16 +299,17 @@ def print_search_results(mags, sizes, uploaded):
try: try:
ratio = no_seeders / no_leechers ratio = no_seeders / no_leechers
except ZeroDivisionError: except ZeroDivisionError:
ratio = 0 ratio = float('inf')
# Alternate between colors # Alternate between colors
cur_color = 'zebra_0' if (cur_color == 'zebra_1') else 'zebra_1' cur_color = 'zebra_0' if (cur_color == 'zebra_1') else 'zebra_1'
torrent_name = parse.unquote(name.group(1)).replace('+', ' ') torrent_name = parse.unquote(name.group(1)).replace('+', ' ')
# enhanced print output with justified columns # enhanced print output with justified columns
print("%5d %6d %6d %5.1f %-11s %-11s %-*s" % ( print('{:4} {:5} {:5} {:5.1f} {:5.1f} {:3} {:>11} {:{length}}'.format(
m, no_seeders, no_leechers, ratio ,sizes[m], m, no_seeders, no_leechers, ratio, float(sizes[m][0]),
uploaded[m], columns, torrent_name), color=cur_color) sizes[m][1], uploaded[m], torrent_name, length=columns),
color=cur_color)
def print_descriptions(chosen_links, mags, site, identifiers): def print_descriptions(chosen_links, mags, site, identifiers):
@ -513,14 +515,12 @@ def main():
elif code == 'p': elif code == 'p':
print_search_results(mags, sizes, uploaded) print_search_results(mags, sizes, uploaded)
elif not l: elif not l:
print('No links entered!') print('No links entered!', color='WARN')
else: else:
break break
except Exception as e: except Exception as e:
print('Exception:', color="ERROR") print('Exception:', e, color='ERROR')
print(str(e))
choices = () choices = ()
sys.exit(1)
if config.getboolean('SaveToFile', 'enabled'): if config.getboolean('SaveToFile', 'enabled'):
# Save to file is enabled # Save to file is enabled
@ -540,8 +540,7 @@ def main():
else: else:
# use transmission as default # use transmission as default
for choice in choices: for choice in choices:
choice = int(choice) url = mags[int(choice)][0]
url = mags[choice][0]
print(url) print(url)
if args.transmission: if args.transmission:
os.system('transmission-remote --add "%s" ' % (url)) os.system('transmission-remote --add "%s" ' % (url))