-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheoat-split.py
More file actions
executable file
·36 lines (29 loc) · 961 Bytes
/
Copy patheoat-split.py
File metadata and controls
executable file
·36 lines (29 loc) · 961 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*
import re
import sys
import argparse
parser = argparse.ArgumentParser(description='eoat-split - splits a text files into multiple text files using a specified delimiter')
parser.add_argument('-i','--input', help='Input file', required=True)
parser.add_argument('-d','--delimiter',help='Chapter or section delimiter, for example, CHAPTER', required=True)
args = parser.parse_args()
if (args.input):
input_file = args.input
print("Found input file as " + input_file)
else:
exit
if (args.delimiter):
delimiter = args.delimiter
print("Found chapter delimiter as " + delimiter)
else:
exit
with open(input_file, 'r',encoding='utf-8') as file:
txt = file.read()
num = 0
output = re.split(delimiter, txt)
for line in output:
chap = open(str(num).zfill(3) + ".md",'w',encoding='utf-8')
chap.write("# " + delimiter + line + "\n")
chap.close()
num = num + 1
print(num)