summaryrefslogtreecommitdiff
path: root/tools/genlayout.py
diff options
context:
space:
mode:
authorMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-10-27 22:16:17 +0200
committerMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-10-27 22:16:17 +0200
commitb38e8565e9023adf5e0761a2102c2d1f275f67de (patch)
treea2ea86c8e8055301b51b55a6ba98063889aa3eba /tools/genlayout.py
parent400f3866eb7103243d5f52bcd17a0251dcc36304 (diff)
downloadvotes-for-women-b38e8565e9023adf5e0761a2102c2d1f275f67de.tar.gz
generated layout for cubes & supporter placement
Diffstat (limited to 'tools/genlayout.py')
-rw-r--r--tools/genlayout.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/genlayout.py b/tools/genlayout.py
new file mode 100644
index 0000000..8782af3
--- /dev/null
+++ b/tools/genlayout.py
@@ -0,0 +1,32 @@
+from bs4 import BeautifulSoup
+
+SCALE = 1.0
+
+def readsvg(filename):
+ with open(filename) as fp:
+ soup = BeautifulSoup(fp, features="xml")
+
+ result = []
+ for group in ['Regions', 'States']:
+ boxes = soup.find('g', id=group)
+ for box in boxes.find_all('g', recursive=False):
+ name = box.attrs['id']
+ rect = box.find('rect')
+ x = float(rect.attrs['x'])
+ y = float(rect.attrs['y'])
+ w = float(rect.attrs['width'])
+ h = float(rect.attrs['height'])
+ xc = round((x+w/2.0)*SCALE)
+ yc = round((y+h/2.0)*SCALE)
+ result.append([name, xc, yc])
+
+ return result
+
+def print_list(data):
+ print("const LAYOUT = {")
+ for (name, x, y) in data:
+ print(f'\t"{name}": [{x}, {y}],')
+ print("}")
+
+result = readsvg("tools/layout.svg")
+print_list(result)