Add option to color svg file itself with GET argument

This commit is contained in:
2017-11-16 21:52:28 +01:00
parent d46b006032
commit 9532d3ba66
2 changed files with 16 additions and 7 deletions
+12 -5
View File
@@ -17,13 +17,20 @@ def list_collections():
if not i.endswith(".svg"):
yield os.path.basename(i)
@memoize
def get(name):
def get(name, color=None):
with open(os.path.join(config.svgdir, f"{name}.svg"), "r") as f:
return f.read()
if not color:
return f.read()
return (f.read() #EW!
.replace("style=\"fill:#", f"style=\"fill:#{color};")
.replace("style='fill:#", f"style='fill:#{color};")
.replace("fill=\"#", f"fill=\"#{color}\" asdasd=\"")
.replace("fill='#", f"fill='#{color}' asdasd='")
.replace("<svg", f"<svg fill=\"#{color}\"")
)
def store(name, data):
with open(os.path.join(config.svgdir, f"{name}.svg"), "wb" if type(data) is bytes else "w") as f: