Created
December 20, 2012 05:45
-
-
Save justinwoo/4343194 to your computer and use it in GitHub Desktop.
takes text from your clipboard and colors it in html using a generated colorbank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate a color bank from a file and feed into colorbank.txt | |
#use a mutable set to avoid duplicates | |
from sets import Set | |
colors = Set() | |
#get my colors from the file | |
finlines = open('sourcecolors.txt','r').readlines() | |
#sourcecolors.txt is the page source ripped from http://www.color-hex.com/. | |
for line in finlines: | |
index = line.find('#') | |
if index != -1: | |
color = line[index:index+7] | |
colors.add(color) | |
#write em out | |
f = open('colorbank.txt', 'w') | |
f.write('\n'.join(colors)) | |
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#take your clipboard's text and colorize it with the color bank | |
import win32clipboard as clippy | |
import random as randy | |
colorlist = [] | |
def main(): | |
#gotta do this for clip board stuff | |
clippy.OpenClipboard() | |
cliptext = clippy.GetClipboardData() | |
#wonderful color list that we work with | |
initializeColorlist() | |
#we gonna just make a new string and everything to it | |
outtext = '' | |
for char in cliptext: | |
if char is not " ": | |
outtext += "<span style= ""color:" + pickacolor() + " "">" | |
outtext += char | |
outtext += "</span>" | |
else: | |
outtext += "<span> </span>" | |
clippy.EmptyClipboard() | |
clippy.SetClipboardText(outtext) | |
clippy.CloseClipboard() | |
def initializeColorlist(): | |
finlines = open('colorbank.txt','r').readlines() | |
for line in finlines: | |
colorlist.append(line) | |
def pickacolor(): | |
return str(randy.sample(colorlist,1))[2:9] | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment