Files
gallery/static/src/lib/weather-icons/icons_optimizator.py
T
2026-08-21 20:10:58 +03:00

35 lines
851 B
Python

# pylint: skip-file
from pathlib import Path
from lxml import etree
def normalize_value(value: str) -> str:
try:
return f"{float(value):.2f}"
except ValueError:
pass
return value
def icon_optimizator(file: Path):
source_size = file.stat().st_size
tree = etree.parse(file)
for node in tree.findall(".//{*}path"):
d = node.attrib["d"]
node.attrib["d"] = " ".join(map(normalize_value, d.split(" ")))
# file = file.parent.parent / "icons.tmp" / file.name
# file.parent.mkdir(parents=True, exist_ok=True)
tree.write(file)
target_size = file.stat().st_size
print(file.name, source_size, target_size)
def icons_optimizator():
for file in (Path(__file__).parent / "icons").glob("*.svg"):
icon_optimizator(file)
if __name__ == "__main__":
icons_optimizator()