-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSCCB_Bible_Commentary_Cull.py
52 lines (45 loc) · 1.36 KB
/
USCCB_Bible_Commentary_Cull.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#USCCB Bible Commentary Cull
#for personal use only
from os import listdir, path, chdir, makedirs, rename
def cull_commentary(txt):
lines = txt.split('\n')
culled = []
for l in lines:
if len(l) < 7:
culled.append(l)
continue
if l[1] == ".": continue
if l[0] == "*": continue
culled.append(l)
return '\n'.join(culled)
def cull_book(settings):
name = settings[0]
chaps = settings[1]
h = get_bible_book(name,chaps)
fnm = name + ".txt"
f = open(fnm, mode='w',encoding="utf-8")
f.write(h)
f.close()
print("saved",fnm)
def process_files(files, ext):
'''Move the originals and save a culled version in the root'''
bkpdirname = "NAB_With_Commentary"
bkpdir = f"./{bkpdirname}/"
if not bkpdirname in files:
makedirs(bkpdir)
for f in files:
if f.endswith(ext):
with open(f, encoding="utf-8") as file:
contents = file.read()
contents = cull_commentary(contents)
m = bkpdir + f
rename(f, m)
fl = open(f, "w",encoding="utf-8")
fl.write(contents)
fl.close()
if __name__ == '__main__':
dir_path = path.dirname(path.realpath(__file__))
chdir(dir_path)
all_files = listdir()
target_extension = ".txt"
process_files(all_files, target_extension)