Blame view

egs/iam/v1/local/remove_wellington_annotations.py 1.14 KB
8dcb6dfcb   Yannick Estève   first commit
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
  #!/usr/bin/env python3
  # Copyright 2018 Chun-Chieh Chang
  
  import sys
  import io
  import re
  from collections import OrderedDict
  
  sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding="utf8");
  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf8");
  
  prev2_line = " ";
  prev_line = " ";
  for line in sys.stdin:
      line = line.strip()
      pattern = re.compile("\\*\\*\\[.*?\\*\\*\\]|\\*[0-9]|\\\\[0-9]{0,2}|\\*\\*?[\|,\?,\#,\=,\;,\:,\<,\>]|\||\^")
      line_fixed = pattern.sub("", line)
      dict=OrderedDict([("*+$","$"), ("*+","£"), ("*-","-"), ("*/","*"), ("*{","{"), ("*}","}"),
          ("**\"","\""), ("*\"","\""), ("**'","'"), ("*'","'"), ("*@","°")])
      pattern = re.compile("|".join(re.escape(key) for key in dict.keys()));
      line_fixed = pattern.sub(lambda x: dict[x.group()], line_fixed)
      
      line_fixed = prev2_line + "
  " + prev_line + "
  " + line_fixed
  
      pattern = re.compile("\{[0-9]{0,2}(.*?)\}", re.DOTALL)
      line_fixed = pattern.sub(lambda x: x.group(1), line_fixed)
  
      output, prev2_line, prev_line = line_fixed.split("
  ")
  
      sys.stdout.write(output + "
  ")
  sys.stdout.write(prev2_line + "
  ")
  sys.stdout.write(prev_line + "
  ")