-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenerate_graph.py
More file actions
executable file
·46 lines (34 loc) · 1.3 KB
/
generate_graph.py
File metadata and controls
executable file
·46 lines (34 loc) · 1.3 KB
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
#!/usr/bin/env python
import yaml
import pystache
import json
import pprint
def truncword(content, length, suffix):
return content if len(content) <= length else content[:length-len(suffix)].rsplit(' ', 1)[0] + suffix
with open("CitySDK-palaute.yaml") as stream:
apidoc = yaml.safe_load(stream)
with open("palaute-graph.gvt") as stream:
template = stream.read()
defs = apidoc['definitions']
context = []
for definition in defs:
formatted = {}
# Need to replace pystache with something more capable, but too tired
formatted['name'] = definition
keys = ['title', 'description']
for k in keys:
if k in defs[definition]:
formatted[k] = defs[definition][k]
formatted['properties'] = []
for prop in defs[definition]['properties']:
property = defs[definition]['properties'][prop]
if 'title' in property:
desc = property['title']
elif 'description' in property:
desc = property['description']
else:
desc = prop
formatted['properties'].append({'name': prop, 'description': truncword(desc, 60, "...")})
context.append(formatted)
rendis = pystache.Renderer(string_encoding='utf-8', missing_tags="strict")
print rendis.render(template, {'c': context}).encode('utf-8')