Created
May 8, 2019 19:54
-
-
Save Bouni/f573c7de9acd06a2c103c7ea4e6f1e84 to your computer and use it in GitHub Desktop.
Export KNX Adresses from .knxproj file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import re | |
import zipfile | |
if len(sys.argv) != 2: | |
print("Please pass .knxproj file as argument") | |
def ga(num): | |
num = int(num) | |
return f"{(num & 0x7800) >> 11}/{(num & 0x700) >> 8}/{num & 0xff}" | |
z = zipfile.ZipFile(sys.argv[1]) | |
xml = next(n for n in z.namelist() if "0.xml" in n) | |
data = z.read(xml).decode("utf-8") | |
res = re.findall(r"GroupAddress.*Address=\"(\d+)\".*Name=\"([^\"]+)\"",data) | |
with open("export.txt", "w") as ex: | |
for r in res: | |
ex.write(f"{ga(r[0]):<15}{r[1]}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment