forked from ghostwires/transcripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_posts.py
103 lines (98 loc) · 3.23 KB
/
edit_posts.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from os import walk
def index_end(string, sub):
#returns the next index after the end of the first occurrence of [sub] in [string]
try:
return string.index(sub) + len(sub)
except:
return -1
def insert(string, index, sub):
#returns a new string with [sub] inserted so the first character of [sub] is at [index] in [string]
new_string = string[:index] + sub + string[index:]
return new_string
def delete(string, index, sub):
new_string = string[:index] + string[(index + len(sub)):]
return new_string
f = []
for (dirpath, dirnames, filenames) in walk('_posts'):
f.extend(filenames)
break
f = sorted(f)
# print(f)
for path in f:
fin = open('_posts/' + path)
text = str(fin.read())
fin.close()
try:
ind = index_end(text, "title_prefix:")
if ind < 0:
pass
else:
while text[ind].isspace():
ind += 1
if text[ind:(ind + 6)] == "\"SEAS\"":
ind = index_end(text, "episode_type:")
while text[ind].isspace():
ind += 1
if text[ind:(ind + 7)] == "special":
text = text.replace("special", "[\"special\", \"belowdecks\"]", 1)
else:
pass
except:
pass
# try:
# ind = index_end(text, "prev_categories:")
# if ind < 0:
# pass
# else:
# while text[ind].isspace():
# ind += 1
# endind = ind
# while text[endind] != ']':
# endind += 1
# prev_categories = text[(ind + 1):(endind)].split(',')
# # print(prev_categories)
# prev_prefixes = []
# for cat in prev_categories:
# if cat == '"tma"':
# prev_prefixes.append('"MAG"')
# elif cat == '"rqg"':
# prev_prefixes.append('"RQG"')
# addition = ', '.join(prev_prefixes)
# # print(addition)
# ind = index_end(text, "prev_prefixes:")
# while text[ind].isspace():
# ind += 1
# ind += 1
# text = insert(text, ind, addition)
# except:
# pass
# try:
# ind = index_end(text, "next_categories:")
# if ind < 0:
# pass
# else:
# while text[ind].isspace():
# ind += 1
# endind = ind
# while text[endind] != ']':
# endind += 1
# next_categories = text[(ind + 1):(endind)].split(',')
# # print(next_categories)
# next_prefixes = []
# for cat in next_categories:
# if cat == '"tma"':
# next_prefixes.append('"MAG"')
# elif cat == '"rqg"':
# next_prefixes.append('"RQG"')
# addition = ', '.join(next_prefixes)
# # print(addition)
# ind = index_end(text, "next_prefixes:")
# while text[ind].isspace():
# ind += 1
# ind += 1
# text = insert(text, ind, addition)
# except:
# pass
fout = open('_posts/' + path, 'w')
fout.write(text)
fout.close()