0

Here is last part of python script, where i am printing following values.

for i in data:
        print i[2], '|', i[12], '\t|', i[24].split('@')[-1], '\t|' , i[9]

Output:

[root@tux work]# ./fs.py
2015-04-24 11:53:31 | RINGING   |       N/A            | 15035205973
2015-04-24 11:53:31 | DOWN      |       N/A            | 00100017063156582
2015-04-24 11:53:33 | RINGING   |       N/A            | 19516828036
2015-04-24 11:53:00 | ACTIVE    | 72.xx.xx.120         | 19093929436
2015-04-24 11:53:05 | ACTIVE    | 72.xx.xx.120         | 13372528024

I am trying to implement color text printing using above table status column RINGING, ACTIVE, DOWN

i[12] holding status column

if RINGING = 'Yellow'
if ACTIVE  = 'Green'
if DOWN    = 'Red'

I found following post which is really good but don't know how it will fit in for loop

Python Print Color Text

Community
  • 1
  • 1
Satish
  • 16,544
  • 29
  • 93
  • 149
  • If you want more control over terminal output, you could take a look at the [blessings](https://pypi.python.org/pypi/blessings/) library. – Ben Apr 24 '15 at 18:40

1 Answers1

1

Create a dict to hold the colors:

COLORS = {"RINGING": '\033[93m', "ACTIVE": '\033[92m', "DOWN": '\033[91m', "ENDC": '\033[0m'}

Then just do something like:

for i in data:
    print COLORS[i[12]],
    print i[2], '|', i[12], '\t|', i[24].split('@')[-1], '\t|' , i[9],
    print COLORS["ENDC"]
Ella Sharakanski
  • 2,683
  • 3
  • 27
  • 47
  • Superb! but its working, but its printing `newline` between each line, How do i remote that? – Satish Apr 24 '15 at 17:26
  • I figured out, i did this `print i[2], '|', COLORS[i[12]], i[12] + bcolors.ENDC + '\t|', i[24].split('@')[-1], '\t|' , i[9]` – Satish Apr 24 '15 at 17:31