#!/usr/bin/env python3 import click from BDSM import app, db from BDSM.models import Settings, Toot, Other from BDSM.toot import app_login, toot_process from mastodon import MastodonNotFoundError @app.cli.command() @click.option('--drop', is_flag=True, help='Create after drop.') def initdb(drop): """Initialize the database.""" if drop: db.drop_all() db.create_all() click.echo('Initialized database.') @app.cli.command() def renderfile(): """render toot""" from BDSM.models import Toot from BDSM.views import process_toot from jinja2 import Environment, FileSystemLoader head = '''
''' def render_toot(toot_id): _toot = [] toot = Toot.query.get(toot_id) if toot == None: return "None" _toot.append(toot) _toot = process_toot(_toot) env = Environment(loader=FileSystemLoader("./BDSM/templates")) jinja_template = env.get_template("toot.html") template_string = jinja_template.render(toots=_toot) return template_string def _render(input_file): env = Environment(loader=FileSystemLoader("./")) jinja_template = env.get_template(input_file) jinja_template.globals.update(render_toot=render_toot) template_string = jinja_template.render() with open('./output.html', 'w') as f: f.write(head + template_string + '