NekoCT is a reusable web comment server intended for frame-based inclusion in static websites.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

100 lines
2.6 KiB

#!/usr/bin/env python
"""
NekoCT is a reusable web comment server intended for frame-based inclusion in static websites.
"""
__author__ = 'Nablachi'
__version__ = '0.0.1'
__license__ = 'AGPL-v3.0' # SEE LICENSE FILE
import toml, json, bottle_sqlite
from bottle import Bottle, run, template, BaseTemplate, static_file, redirect, ext
from argparse import ArgumentParser
app = Bottle()
def prepare(db):
db.execute('CREATE TABLE IF NOT EXISTS textcache (hash INTEGER PRIMARY KEY, data TEXT) WITHOUT ROWID')
db.execute('''CREATE TABLE IF NOT EXISTS boards (
id INTEGER PRIMARY KEY,
titlece INTEGER NOT NULL,
count INTEGER
) WITHOUT ROWID''')
db.execute('''CREATE TABLE IF NOT EXISTS posts (
board INTEGER NOT NULL,
postid INTEGER NOT NULL,
replyto INTEGER NOT NULL,
date INTEGER NOT NULL,
unamece INTEGER NOT NULL,
uuid INTEGER NOT NULL,
ptextce INTEGER NOT NULL,
PRIMARY KEY(board, postid, replyto)
) WITHOUT ROWID''')
db.execute('CREATE INDEX IF NOT EXISTS idx_posts_date ON posts (date)')
@app.route('/')
def index(db):
prepare(db)
@app.route('/c')
def boardcreate(db):
prepare(db)
return template("create.tpl")
@app.route('/b/<gbid:int>')
def boardview(gbid: int, db):
prepare(db)
@app.route('/static/<filename:path>')
def send_static(filename):
return static_file(filename, root='./static')
parser = ArgumentParser(
description = ('NekoCT is a reusable web comment server intended for frame-based inclusion in static websites.')
)
parser.add_argument(
'-H', '--host',
type = str,
default = '0.0.0.0',
help = ('The IP to bind to. Binds to 0.0.0.0 by default.')
)
parser.add_argument(
'-P', '--port',
type = int,
default = 8080,
help = ('The port to bind to. Binds to 8080 by default.')
)
parser.add_argument(
'-w', '--wsgi',
type = str,
default = 'bjoern',
help = ('Specifies what WSGI server to use. Defaults to bjoern.')
)
parser.add_argument(
'-c', '--config',
type = str,
default = 'config.toml',
help = ('Specifies where to find the config file. Defaults to config.json in the current working directory.')
)
parser.add_argument(
'-d', '--debug',
action = 'store_true',
help = 'Enable debug mode and auto-reloader.'
)
args = parser.parse_args()
app.config.load_dict(toml.load(args.config))
BaseTemplate.defaults['gconfig'] = app.config
app.install(bottle_sqlite.Plugin(dbfile=app.config['database.path']))
if args.debug:
run(app, host=args.host, port=args.port, reloader=True, debug=True)
else:
run(app, host=args.host, port=args.port, server=args.wsgi)