-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.py
35 lines (32 loc) · 1003 Bytes
/
format.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
import os
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
if len(sys.argv) < 2:
raise ValueError
path = sys.argv[1].encode('utf-8').strip()
# print path
for filename in os.listdir(path):
contents = ''
with open(path + '/' + filename , 'r') as file:
contents = file.readlines()
multi = True
if len(contents) == 1:
contents = contents[0]
multi = False
with open(path + '/' + filename , 'w') as file:
if multi:
for wizard in contents:
file.write(wizard.rstrip() + ' ')
else:
arr = (find_between(contents, '[', ']')[1: -1]).split(',')
ordering = [a.strip().strip("'").strip() for a in arr]
for wizard in ordering:
file.write(wizard + ' ')