Skip to content

Commit a39c140

Browse files
committed
converts review txt files to basic formatted md files
1 parent 4acf8c6 commit a39c140

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

review_to_md/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+

0 commit comments

Comments
 (0)