misc/rainbow.py

27 lines
681 B
Python
Raw Normal View History

2017-11-26 00:15:05 -05:00
#! /usr/bin/env python3
# coding=utf-8
import sys, time
#timeStart = time.time()
rainbow = "rrooyyYYGGggccCCBBbbmmMM"
colorCode = {'r':5, 'o':4, 'y':7, 'Y':8, 'g':3, 'G':9, 'c':10, 'C':11, 'b':2, 'B':12, 'm':6, 'M':13, 0:1, 1:14, 2:15, 'w':0}
with open(sys.argv[1], 'r+', encoding="utf-8") as file:
lines = file.readlines()
rainbowified = ""
start = 0
for line in lines:
n = (start % len(rainbow))
for char in line:
rainbowified = rainbowified + '\x03' + str(colorCode[rainbow[(n % len(rainbow))]]) + char
n = n + 1
start = start + 1
print(rainbowified)
#with open('./test', 'w+') as file:
# file.write(rainbowified)
#timeEnd = time.time()
#print(timeEnd - timeStart)