#!/usr/bin/env python3 import sys import colorsys def hsl2hex(color): # regex = r'hsl\(\s*(\d+),\s*(\d+)%,\s*(\d+)%\s*\);' # lines = [re.findall(regex,line) for line in one_dark_syn.split('\n')] # rgbs = [colorsys.hsv_to_rgb(int(line[1][0])/360, int(line[0][1])/100, int(line[0][2])/100) for line in lines if line] # rgbhex = ["".join("%03X" % round(i*255) for i in rgb) for rgb in rgbs] colors = color.split(",") color_rgb_frac = colorsys.hls_to_rgb(int(colors[0]) / 360, int(colors[2]) / 100, int(color[1]) / 100) print(color_rgb_frac) color_rgb = [round(value / 255) for value in color_rgb_frac] print(color_rgb) color_hex = [",".join("%3X" % rgb for rgb in color_rgb)] print(color_hex) return color_hex # https://www.rapidtables.com/convert/color/hsl-to-rgb.html if __name__ == "__main__": if sys.argv[1] == "hsl2hex": print(hsl2hex(sys.argv[2])) else: print("Usage example:\ncolorconvert hsl2hex 78,50,60")