-
Notifications
You must be signed in to change notification settings - Fork 1
/
bars.py
executable file
·35 lines (29 loc) · 1010 Bytes
/
bars.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# replaces column(s) with ascii bars
import sys
import argparse
# ----- command line parsing -----
parser = argparse.ArgumentParser(
prog="bars",
formatter_class=argparse.RawDescriptionHelpFormatter,
description="Turns some columns into ASCII bars.")
parser.add_argument("column", type=int,
help="Column to use for bars.")
parser.add_argument("-w", "--width", type=int, default=20,
help="Width of bars.")
parser.add_argument("-d", "--delimiter", type=str,
help="Column delimeter.")
args = parser.parse_args()
# ----- end command line parsing -----
lines = []
lengths = []
bars = []
for line in sys.stdin:
lines.append(line[:-1])
lengths.append(len(line)-1)
bars.append(float(line.split(args.delimiter)[args.column-1]))
mbar = max(bars)
mlen = max(lengths)
for line, bar in zip(lines, bars):
sys.stdout.write(line.ljust(mlen) + " ")
sys.stdout.write("*" * int(bar/mbar * args.width) + "\n")