-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplit.py
More file actions
29 lines (26 loc) · 743 Bytes
/
split.py
File metadata and controls
29 lines (26 loc) · 743 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
import sys, os
SONG_DEL = '\\beginsong{'
BAN_CHARS = '\\&/()'
def split(data, todir):
songs = data.split(SONG_DEL)[1:]
for song in songs:
write(song, todir)
def write(song, todir):
name = song.split('}', 1)[0]
if 'by={' in song:
author = ' - ' + song.split('by={', 1)[1].split('}]', 1)[0]
for char in BAN_CHARS:
if char in author:
author = ''
break
else:
author = ''
fn = todir + '\\' + name + author + '.tex'
with open(fn, 'w', encoding='utf8') as outfile:
outfile.write(SONG_DEL + song)
if __name__ == '__main__':
with open(sys.argv[1], encoding='utf8') as mainfile:
todir = sys.argv[2]
if not os.path.exists(todir):
os.mkdir(todir)
split(mainfile.read(), todir)