summaryrefslogtreecommitdiff
path: root/seq-ateurs.py
blob: c5ff9b6ccfd3b11e5906a0c9536ca6381007f34b (plain)
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
#!/usr/bin/env python3
import plantuml
import sys
import time
import os

f = open(sys.argv[1], 'r').readlines()
p = plantuml.PlantUML(url="http://www.plantuml.com/plantuml/svg/")


def generate_svg(name, text):
    print(f"generating: {text}")
    try:
        res = p.processes(plantuml_text=(text))
    except Exception:
        print(p.get_url(plantuml_text=(text)))
        return

    svg = 'seq/' + name + '.svg'
    pdf = 'seq/' + name + '.pdf'
    open(svg, 'wb').write(res)
    os.system(f"inkscape {svg} -o {pdf}")
    time.sleep(1)


def parse_sequence(offset):
    print(f"offset: {offset}")
    while not "```plantuml" == f[offset].strip():
        offset += 1
    begin = offset
    while not "```" == f[offset].strip():
        offset += 1
    lines = f[begin + 1:(offset - 1)]
    name = f[begin + 1][1:-1]
    print(f"name: {name}")
    generate_svg(name, ''.join(lines))
    return offset


offset = 0
while offset < len(f):
    offset = parse_sequence(offset)