Added scribus support
This commit is contained in:
41
main.py
41
main.py
@@ -1,23 +1,38 @@
|
|||||||
import sys
|
import sys
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
def main(input, output):
|
def main(file_format, input, output):
|
||||||
|
|
||||||
with open(input, newline='') as csvfile, open(output, "w") as gpl:
|
with open(input, newline='') as csvfile, open(output, "w") as out:
|
||||||
code_reader = csv.reader(csvfile, delimiter=',')
|
code_reader = csv.reader(csvfile, delimiter=',')
|
||||||
next(code_reader)
|
next(code_reader)
|
||||||
|
|
||||||
gpl.write(f"GIMP Palette\n")
|
match file_format:
|
||||||
gpl.write(f"Name: Swatchos\n")
|
case "gpl":
|
||||||
gpl.write(f"Columns: 0\n")
|
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'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||||
|
out.write(f'<SCRIBUSCOLORS Name="{output}">\n')
|
||||||
|
for row in code_reader:
|
||||||
|
c = float(row[1])/100
|
||||||
|
m = float(row[2])/100
|
||||||
|
y = float(row[3])/100
|
||||||
|
k = float(row[4])/100
|
||||||
|
out.write(f'<COLOR Spot="0" Register="0" Name="{row[0]}" CMYK="{c} {m} {y} {k}"/>\n')
|
||||||
|
out.write(f"</SCRIBUSCOLORS>")
|
||||||
|
|
||||||
for row in code_reader:
|
|
||||||
hex = row[1].lstrip('#')
|
|
||||||
r = int(hex[0:2], 16)
|
|
||||||
g = int(hex[2:4], 16)
|
|
||||||
b = int(hex[4:6], 16)
|
|
||||||
|
|
||||||
gpl.write(f"{r} {g} {b} {row[0]}\n")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv[1], sys.argv[2])
|
|
||||||
|
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])
|
||||||
|
|||||||
Reference in New Issue
Block a user