UnderCover/flaskr/__init__.py

54 lines
1.3 KiB
Python
Raw Normal View History

# Copyright Sage Vaillancourt 2021
import os
import time
import subprocess
from flask import (
Flask, redirect, url_for, render_template, send_from_directory
)
2021-07-23 23:09:08 -04:00
import writing
INDEX = None
def optimize_css():
import re
root = os.path.dirname(os.getcwd())
static_dir = root + '/undercover/flaskr/static/'
css = open(static_dir + 'styles.css', 'r').read()
minified_with_comments = "".join(list(map(
lambda line: line if 'media' in line else line.replace(' ', ''),
css.split('\n')
)))
minified = re.sub( r'/\*[\s\S]*?\*/', "", minified_with_comments)
minified_file = open(static_dir + 'styles_min.css', 'w')
minified_file.write(minified)
minified_file.close()
def create_app(test_config=None):
optimize_css()
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev',
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
)
if test_config is None:
app.config.from_pyfile('config.py', silent=True)
else:
app.config.from_mapping(test_config)
try:
os.makedirs(app.instance_path)
except OSError:
pass
app.register_blueprint(
2021-07-23 23:09:08 -04:00
writing.writing_blueprint,
#url_prefix='/writing',
)
return app