Advertisement
ijontichy

tmp2.py

Apr 15th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import string
  2.  
  3. derp = open("herp.txt", "w")
  4. colors = {}
  5. strs = []
  6.  
  7. for line in open("/etc/X11/rgb.txt", "r"):
  8.     if line[0] == "!":
  9.         continue
  10.    
  11.     vals = line.split()
  12.    
  13.     hexColor = ""
  14.  
  15.     for val in vals[:3]:
  16.         hexPart = hex(int(val))[2:]
  17.         hexPart = ("0" * (2 - len(hexPart))) + hexPart
  18.  
  19.         hexColor = hexColor + hexPart
  20.  
  21.     niceName = " ".join(vals[3:])
  22.     niceTmp  = []
  23.  
  24.     for i, char in enumerate(niceName):
  25.  
  26.         if char in string.ascii_uppercase:
  27.  
  28.             if lastChar in string.ascii_lowercase:
  29.                 niceTmp.extend([" ", char.lower()])
  30.  
  31.             else:
  32.                 niceTmp += char.lower()
  33.  
  34.         elif char in string.digits:
  35.  
  36.             if lastChar not in string.digits:
  37.                 niceTmp.extend([" ", char])
  38.  
  39.             else:
  40.                 niceTmp += char
  41.  
  42.         else:
  43.             niceTmp += char
  44.  
  45.         lastChar = char
  46.  
  47.     niceName = "".join(niceTmp)
  48.     niceName = niceName.strip()
  49.  
  50.     if hexColor not in colors:
  51.         colors[hexColor] = niceName
  52.  
  53. colorList = []
  54. nameList  = []
  55.  
  56. for color in sorted(colors, key=(lambda x: colors[x])):
  57.     colorList.append(color)
  58.     nameList.append(colors[color])
  59.  
  60. colorListStr = "int hexStrs[{}] = {{\"{}\"}};\n\n".format(len(colorList), "\", \"".join(colorList))
  61. nameListStr  = "int hexNams[{}] = {{\"{}\"}};\n\n".format(len(nameList), "\", \"".join(nameList))
  62.  
  63.  
  64. derp.write(colorListStr + nameListStr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement