Skip to content

Commit 6fb2d4e

Browse files
authored
Update lightnovel.py
1 parent 8110e9b commit 6fb2d4e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lightnovel.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def load_dt_map():
2525
dt_map = {}
2626
lines = open('dt.txt', encoding='utf-8') \
2727
.read().split('\n')
28-
lines = filter(None, map(lambda x: x.strip()))
28+
lines = filter(None, map(lambda x: x.strip(), lines))
2929
lines = filter(lambda x: len(x) >= 2,
30-
map(lambda x: x.split(' ')))
30+
map(lambda x: x.split(' '), lines))
3131
for l in lines: dt_map[l[0]] = l[1]
3232
return dt_map
3333

@@ -141,8 +141,12 @@ def get_toc(html):
141141
for i in range(len(el_links)):
142142
id = re.search(r'/(\d+)\.htm', el_links.eq(i).attr('href')).group(1)
143143
dt = el_dts.eq(i).text().split('/')[0][3:].replace('-', '')
144-
if dt != '':
145-
res.append({'id': id, 'dt': dt})
144+
res.append({'id': id, 'dt': dt})
145+
for i in range(1, len(res)):
146+
res[i]['dt'] = res[i]['dt'] or res[i - 1]['dt']
147+
for i in range(len(res) - 2, -1, -1):
148+
res[i]['dt'] = res[i]['dt'] or res[i + 1]['dt']
149+
res = [r for r in res if r['dt']]
146150
return res
147151

148152

0 commit comments

Comments
 (0)