From a98df138ef5684c97652898e9bab7a90e58f2995 Mon Sep 17 00:00:00 2001 From: Grex Date: Fri, 8 Jan 2021 10:53:09 +0100 Subject: [PATCH] svg_combiner for python 3 sudo apt -y install python3-pip pip3 install requests --- svg_combiner-python3.py | 97 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 svg_combiner-python3.py diff --git a/svg_combiner-python3.py b/svg_combiner-python3.py new file mode 100644 index 0000000..a2c5891 --- /dev/null +++ b/svg_combiner-python3.py @@ -0,0 +1,97 @@ + +import json +import requests +import time +import urllib.parse as urlparse +import sys +from os import listdir +from os.path import isfile, join +import xml.etree.ElementTree as ET + +t1 = time.time() + +symbols = { 'line-visuals', + 'connection-arw-l', + 'controal-4', + 'double-arrow', + 'down-arrow-2', + 'reload', + 'volume-close', + 'volume-increase', + 'volume', + 'right-arrow-2', + 'right-play', + 'left-arrow-2', + 'stop_1_', + 'top-arrow-2', + 'battery', + 'box', + 'charging-2', + 'charging-3', + 'charging-1', + 'drive-3', + 'drive', + 'flat-tv', + 'floppy', + 'plug', + 'processor', + 'sim-card', + 'window', + 'globe', + 'navigate', + 'clock', + 'direction-n', + 'drop', + 'drops', + 'half-moon', + 'half-light', + 'shade', + 'stars', + 'sun', + 'thermometer-3', + 'wind', + 'umberla', + 'sun-nwave', + 'tree-3' } + +symbol_count = 0 +mypath = '/etc/openhab2/html/matrix-theme/original-svgs' + +onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] + +ET.register_namespace("","http://www.w3.org/2000/svg") +top = ET.Element('svg', attrib = { 'version':'1.1', 'xmlns:xlink':'http://www.w3.org/1999/xlink', 'x':"0px", 'y':"0px", 'viewBox':"0 0 48 48", 'enable-background':"new 0 0 48 48", 'xml:space':"preserve"}) +comment = ET.Comment('Generated by SVG-Combiner') +top.append(comment) + +for file in onlyfiles: + if(file[:1] != '.'): + print ("Processing file: " + file) + + r = requests.get('http://127.0.0.1:8080/static/matrix-theme/original-svgs/' + file) + print (r.status_code) + if(len(r.text)>0): + xml = ET.fromstring(r.text) + for child in xml: + if(len(child.getchildren())>0 and 'id' in child.attrib): + if(child.attrib['id'] in symbols): + for node in child.findall('.//*[@fill]'): + if ('stroke' in node.attrib): node.attrib.pop('stroke') + if ('stroke-width' in node.attrib): node.attrib.pop('stroke-width') + #print child.attrib['id'], ET.tostring(child,encoding='utf8', method='xml') + top.append(child) + symbol_count = symbol_count + 1 + print (" --> added " + child.attrib['id']) + else: + print ("Error processing file: HTTP Response " + str(r.status_code)) + +f = open('/etc/openhab2/html/matrix-theme/squidink.svg', 'wb') +f.write(ET.tostring(top,encoding='utf8', method='xml')) +f.close() + + +t2 = time.time() +print ("Done in " + str(t2-t1) + " seconds " + str(symbol_count) + " symbols created") + + +