File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ from typing import List
3
+ import argparse
4
+
5
+
6
+ def read_review_file (file_path : str ) -> List [str ]:
7
+ formatted_lines : List [str ] = []
8
+ heading : bool = False
9
+ heading_mark = "#"
10
+ if not os .path .exists (file_path ):
11
+ raise Exception ("Incorrect file path" )
12
+ with open (file_path ) as file :
13
+ lines : List [str ] = file .readlines ()
14
+ for line in lines :
15
+ if line .startswith ("==-==" ):
16
+ continue
17
+ elif line .startswith ("==+==" ):
18
+ line = line .replace ("==+==" , heading_mark )
19
+ if not heading :
20
+ heading = True
21
+ heading_mark = "##"
22
+ formatted_lines .append (line )
23
+ return formatted_lines
24
+
25
+
26
+ def write_file (file_path : str , lines : List [str ]):
27
+ # if os.path.exists(file_path):
28
+ # raise Exception("file already exists")
29
+ with open (file_path , "w" ) as file :
30
+ file .writelines (lines )
31
+
32
+
33
+ if __name__ == "__main__" :
34
+
35
+ parser = argparse .ArgumentParser (description = 'Processes review text files\
36
+ and spews out markdown.' )
37
+
38
+ parser .add_argument ("input" , help = "full path to the input file" )
39
+ args = parser .parse_args ()
40
+
41
+ write_file (args .input + "_formatted.md" , read_review_file (args .input ))
42
+
You can’t perform that action at this time.
0 commit comments