File: aafigure_mapper.py

package info (click to toggle)
pyroute2 0.8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,704 kB
  • sloc: python: 50,245; makefile: 280; javascript: 183; ansic: 81; sh: 44; awk: 17
file content (22 lines) | stat: -rw-r--r-- 636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import contextlib
import io
import sys

ret = io.StringIO()

with contextlib.ExitStack() as ctx:
    map_file = ctx.enter_context(open(sys.argv[1], 'r'))
    img_file = ctx.enter_context(open(sys.argv[2], 'r'))

    mapping = {
        key.strip(): value.strip()
        for (key, value) in [x.split('|') for x in map_file.readlines()]
    }
    for line in img_file.readlines():
        if 'a href' not in line:
            for key, value in mapping.items():
                line = line.replace(key, f'  <a href="{value}">{key}</a>')
        ret.write(line)

with open(sys.argv[2], 'w') as img_file:
    img_file.write(ret.getvalue())