<commit_before>#!/usr/bin/env python

import argparse
from glob import glob

from flask import Flask, render_template

import app_config
from render_utils import make_context, urlencode_filter
import static

app = Flask(app_config.PROJECT_NAME)

app.jinja_env.filters['urlencode'] = urlencode_filter

@app.route('/')
def _graphics_list():
    context = make_context()
    context['graphics'] = []

    graphics = glob('www/graphics/*/child.html')
    for graphic in graphics:
        context['graphics'].append(graphic.split('www/graphics/')[1].split('/child.html')[0])

    context['graphics_count'] = len(context['graphics'])

    return render_template('index.html', **context)

@app.route('/graphics/<slug>/')
def _graphics_detail(slug):
    """
    Renders a parent.html index with child.html embedded as iframe.
    """

    context = make_context()
    context['slug'] = slug
    context['domain'] = app_config.S3_BASE_URL

    return render_template('parent.html', **context)

app.register_blueprint(static.static)

# Boilerplate
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--port')
    args = parser.parse_args()
    server_port = 8000

    if args.port:
        server_port = int(args.port)

    app.run(host='0.0.0.0', port=server_port, debug=app_config.DEBUG)<commit_msg>Add per-graphic config file and child.html route. #30.<commit_after>#!/usr/bin/env python

import argparse
from glob import glob
import imp

from flask import Flask, render_template, render_template_string

import app_config
from render_utils import make_context, urlencode_filter
import static

app = Flask(app_config.PROJECT_NAME)

app.jinja_env.filters['urlencode'] = urlencode_filter

@app.route('/')
def _graphics_list():
    """
    Renders a list of all graphics for local testing.
    """
    context = make_context()
    context['graphics'] = []

    graphics = glob('www/graphics/*/child.html')
    for graphic in graphics:
        context['graphics'].append(graphic.split('www/graphics/')[1].split('/child.html')[0])

    context['graphics_count'] = len(context['graphics'])

    return render_template('index.html', **context)

@app.route('/graphics/<slug>/')
def _graphics_detail(slug):
    """
    Renders a parent.html index with child.html embedded as iframe.
    """
    context = make_context()
    context['slug'] = slug
    context['domain'] = app_config.S3_BASE_URL

    return render_template('parent.html', **context)

@app.route('/graphics/<slug>/child.html')
def _graphics_child(slug):
    """
    Renders a child.html for embedding.
    """
    context = make_context()
    
    try:
        graphic_config = imp.load_source('graphic_config', 'www/graphics/%s/graphic_config.py' % slug)
        context.update(graphic_config.__dict__)
    except IOError:
        pass

    with open('www/graphics/%s/child.html' % slug) as f:
        template = f.read().decode('utf-8')

    return render_template_string(template, **context)

app.register_blueprint(static.static)

# Boilerplate
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--port')
    args = parser.parse_args()
    server_port = 8000

    if args.port:
        server_port = int(args.port)

    app.run(host='0.0.0.0', port=server_port, debug=app_config.DEBUG)
{'fraction_non_alphanumeric': 0.140625, 'fraction_numerical': 0.007512019230769231, 'mean_word_length': 3.9318518518518517, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1925952', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1053, 'n_words': 217}