-
Notifications
You must be signed in to change notification settings - Fork 1
/
regions.py
62 lines (53 loc) · 1.58 KB
/
regions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from decimal import Decimal
import xml.dom.minidom as dom
import csv
def walk(node):
if node.nodeType != 1:
return
if node.tagName == 'rect':
x = float(node.getAttribute('x')) / 7200
y = float(node.getAttribute('y')) / 7200
width = float(node.getAttribute('width')) / 7200
height = float(node.getAttribute('height')) / 7200
id = node.getAttribute('id')
if not id.startswith('rect'):
yield (
id,
x,
y,
width,
height,
"http://3rin.gs/#" + ",".join(str(_) for _ in [height, width, y, x])
)
child = node.firstChild
while child:
for row in walk(child):
yield row
child = child.nextSibling
def get():
regions_svg = dom.parse("regions.svg")
return walk(regions_svg.documentElement)
class Region(object):
@property
def diagonal(self):
return (self.width ** 2 + self.height ** 2) ** .5
@property
def size(self):
return self.width, self.height
def regions2():
return dict(
(name, type('region-%s' % str(name), (Region,), dict(
name = name,
x = x,
y = y,
width = width,
height = height,
url = url,
))())
for name, x, y, width, height, url in get()
)
if __name__ == '__main__':
regions_svg = dom.parse("regions.svg")
regions_csv = csv.writer(open("regions.csv", "w"))
for row in walk(regions_svg.documentElement):
regions_csv.writerow(row)