import sys import csv def cmyk_to_hex(cp, mp, yp, kp): c = int(cp * 2.55) m = int(mp * 2.55) y = int(yp * 2.55) k = int(kp * 2.55) return "#{:02x}{:02x}{:02x}{:02x}".format(c,m,y,k) def main(file_format, input, output): output_file_format = "" match file_format: case "gpl": output_file_format = f"{output}.gpl" case "scribus": output_file_format = f"{output}.xml" with open(input, newline='') as csvfile, open(output_file_format, "w") as out: code_reader = csv.reader(csvfile, delimiter=',') next(code_reader) match file_format: case "gpl": out.write(f"GIMP Palette\n") out.write(f"Name: {output}\n") out.write(f"Columns: 0\n") for row in code_reader: hex = row[5].lstrip('#') r = int(hex[0:2], 16) g = int(hex[2:4], 16) b = int(hex[4:6], 16) out.write(f"{r} {g} {b} {row[0]}\n") case "scribus": out.write(f'\n') out.write(f'\n') for row in code_reader: hex = cmyk_to_hex(float(row[1]), float(row[2]), float(row[3]), float(row[4])) out.write(f'\n') out.write(f"") if __name__ == "__main__": if len(sys.argv) != 4: print('Usage: python main.py "format" "input" "output"') sys.exit(1) main(sys.argv[1], sys.argv[2], sys.argv[3])