Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- derp = open("herp.txt", "w")
- colors = {}
- strs = []
- for line in open("/etc/X11/rgb.txt", "r"):
- if line[0] == "!":
- continue
- vals = line.split()
- hexColor = ""
- for val in vals[:3]:
- hexPart = hex(int(val))[2:]
- hexPart = ("0" * (2 - len(hexPart))) + hexPart
- hexColor = hexColor + hexPart
- niceName = " ".join(vals[3:])
- niceTmp = []
- for i, char in enumerate(niceName):
- if char in string.ascii_uppercase:
- if lastChar in string.ascii_lowercase:
- niceTmp.extend([" ", char.lower()])
- else:
- niceTmp += char.lower()
- elif char in string.digits:
- if lastChar not in string.digits:
- niceTmp.extend([" ", char])
- else:
- niceTmp += char
- else:
- niceTmp += char
- lastChar = char
- niceName = "".join(niceTmp)
- niceName = niceName.strip()
- if hexColor not in colors:
- colors[hexColor] = niceName
- colorList = []
- nameList = []
- for color in sorted(colors, key=(lambda x: colors[x])):
- colorList.append(color)
- nameList.append(colors[color])
- colorListStr = "int hexStrs[{}] = {{\"{}\"}};\n\n".format(len(colorList), "\", \"".join(colorList))
- nameListStr = "int hexNams[{}] = {{\"{}\"}};\n\n".format(len(nameList), "\", \"".join(nameList))
- derp.write(colorListStr + nameListStr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement