Skip to content

Instantly share code, notes, and snippets.

@dipu-bd
Last active May 2, 2020 23:53
Show Gist options
  • Save dipu-bd/bcc0fe207f353fc7dd610d2111be4b39 to your computer and use it in GitHub Desktop.
Save dipu-bd/bcc0fe207f353fc7dd610d2111be4b39 to your computer and use it in GitHub Desktop.
Auto generate LN
import os
import time
PUBLIC_DATA = '/etc/lncrawl/public-data'
novels = []
for user in os.listdir(PUBLIC_DATA):
user_dir = os.path.join(PUBLIC_DATA, user)
if not os.path.isdir(user_dir):
continue
for novel in os.listdir(user_dir):
novel_dir = os.path.join(user_dir, novel)
if not os.path.isdir(novel_dir):
continue
formats = []
for fmt in os.listdir(novel_dir):
fmt_dir = os.path.join(novel_dir, fmt)
if not os.path.isdir(fmt_dir):
continue
formats.append([fmt, '%s/%s/%s' % (user, novel, fmt)])
if len(formats) == 0:
continue
novels.append([novel, '%s/%s' % (user, novel), formats])
with open(os.path.join(PUBLIC_DATA, 'index.html'), 'w') as f:
f.write('''
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Lightnovel Crawler</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400&display=swap" rel="stylesheet">
<style>
html, body {
margin: 0;
padding: 10px 15px;
font-family: 'Montserrat', sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 30px;
}
h1 {
font-weight: 300;
line-height: auto;
}
ul {
padding: 15px;
}
</style>
</head>
''')
f.write('''
<body>
<h1>All Novels</h1>
<hr>
<ul>
''')
novels.sort(key=lambda x: x[0])
for novel in novels:
f.write('''
<li>
<a href="%s">%s</a>
&nbsp;&#8680;&nbsp;
''' % (novel[1], novel[0]))
for fmt in novel[2]:
f.write('''
<a href="%s">%s</a>
''' % (fmt[1], fmt[0]))
f.write('''
</li>
''')
f.write('''
</ul>
<hr>
Generated by <a href="https://github.com/dipu-bd/lightnovel-crawler">Lightnovel Crawler</a>
| <code>%s</code>
''' % time.ctime())
f.write('''
</body>
</html>
''')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment