<commit_before>"""Create or serve the pyladies.cz website
"""

import sys
if sys.version_info < (3, 0):
    raise RuntimeError('You need Python 3.')

import os
import fnmatch

from flask import Flask, render_template, url_for, send_from_directory
from flask import redirect
from flask_frozen import Freezer
import yaml
import jinja2
import markdown

from elsa import cli

app = Flask('pyladies_cz')
app.config['TEMPLATES_AUTO_RELOAD'] = True

orig_path = os.path.join(app.root_path, 'original/')
v1_path = os.path.join(orig_path, 'v1/')

########
## Views

@app.route('/')
def index():
    return render_template('index.html')


@app.route('/brno_info/')
def brno_info():
    return render_template('brno_info.html')


@app.route('/praha_info/')
def praha_info():
    return render_template('praha_info.html')

@app.route('/ostrava_info/')
def ostrava_info():
    return render_template('ostrava_info.html')

@app.route('/praha_course/')
def praha_course():
    return render_template('praha_course.html')

@app.route('/brno_course/')
def brno_course():
    return render_template('brno_course.html')

@app.route('/ostrava_course/')
def ostrava_course():
    return render_template('ostrava_course.html')

@app.route('/brno/')
def brno():
    return render_template('brno.html', plan=read_yaml('plans/brno.yml'))


@app.route('/praha/cznic/')
def praha():
    return render_template('praha.html', plan=read_yaml('plans/praha.yml'))

@app.route('/praha/msd/')
def praha_msd():
    return render_template('praha_msd.html', plan=read_yaml('plans/praha_msd.yml'))

@app.route('/ostrava/')
def ostrava():
    return render_template('ostrava.html', plan=read_yaml('plans/ostrava.yml'))

@app.route('/stan_se/')
def stan_se():
    return render_template('stan_se.html')

@app.route('/v1/<path:path>')
def v1(path):
    return send_from_directory(v1_path, path)

@app.route('/index.html')
def index_html():
    return redirect(url_for('index'))

@app.route('/course.html')
def course_html():
    return send_from_directory(orig_path, 'course.html')


##########
## Helpers

md = markdown.Markdown(extensions=['meta', 'markdown.extensions.toc'])

@app.template_filter('markdown')
def convert_markdown(text, inline=False):
    result = jinja2.Markup(md.convert(text))
    if inline and result[:3] == '<p>' and result[-4:] == '</p>':
        result = result[3:-4]
    return result


def read_yaml(filename):
    with open(filename, encoding='utf-8') as file:
        data = yaml.safe_load(file)

    # workaround for http://stackoverflow.com/q/36157569/99057
    # Convert datetime objects to strings
    for lesson in data:
        if 'date' in lesson:
            lesson['date'] = str(lesson['date'])
        if 'description' in lesson:
            lesson['description'] = convert_markdown(lesson['description'],
                                                     inline=True)
        for mat in lesson['materials']:
            mat['name'] = convert_markdown(mat['name'], inline=True)

    return data


def pathto(name, static=False):
    if static:
        prefix = '_static/'<commit_msg>Umožní mít lekci bez materiálů<commit_after>"""Create or serve the pyladies.cz website
"""

import sys
if sys.version_info < (3, 0):
    raise RuntimeError('You need Python 3.')

import os
import fnmatch

from flask import Flask, render_template, url_for, send_from_directory
from flask import redirect
from flask_frozen import Freezer
import yaml
import jinja2
import markdown

from elsa import cli

app = Flask('pyladies_cz')
app.config['TEMPLATES_AUTO_RELOAD'] = True

orig_path = os.path.join(app.root_path, 'original/')
v1_path = os.path.join(orig_path, 'v1/')

########
## Views

@app.route('/')
def index():
    return render_template('index.html')


@app.route('/brno_info/')
def brno_info():
    return render_template('brno_info.html')


@app.route('/praha_info/')
def praha_info():
    return render_template('praha_info.html')

@app.route('/ostrava_info/')
def ostrava_info():
    return render_template('ostrava_info.html')

@app.route('/praha_course/')
def praha_course():
    return render_template('praha_course.html')

@app.route('/brno_course/')
def brno_course():
    return render_template('brno_course.html')

@app.route('/ostrava_course/')
def ostrava_course():
    return render_template('ostrava_course.html')

@app.route('/brno/')
def brno():
    return render_template('brno.html', plan=read_yaml('plans/brno.yml'))


@app.route('/praha/cznic/')
def praha():
    return render_template('praha.html', plan=read_yaml('plans/praha.yml'))

@app.route('/praha/msd/')
def praha_msd():
    return render_template('praha_msd.html', plan=read_yaml('plans/praha_msd.yml'))

@app.route('/ostrava/')
def ostrava():
    return render_template('ostrava.html', plan=read_yaml('plans/ostrava.yml'))

@app.route('/stan_se/')
def stan_se():
    return render_template('stan_se.html')

@app.route('/v1/<path:path>')
def v1(path):
    return send_from_directory(v1_path, path)

@app.route('/index.html')
def index_html():
    return redirect(url_for('index'))

@app.route('/course.html')
def course_html():
    return send_from_directory(orig_path, 'course.html')


##########
## Helpers

md = markdown.Markdown(extensions=['meta', 'markdown.extensions.toc'])

@app.template_filter('markdown')
def convert_markdown(text, inline=False):
    result = jinja2.Markup(md.convert(text))
    if inline and result[:3] == '<p>' and result[-4:] == '</p>':
        result = result[3:-4]
    return result


def read_yaml(filename):
    with open(filename, encoding='utf-8') as file:
        data = yaml.safe_load(file)

    # workaround for http://stackoverflow.com/q/36157569/99057
    # Convert datetime objects to strings
    for lesson in data:
        if 'date' in lesson:
            lesson['date'] = str(lesson['date'])
        if 'description' in lesson:
            lesson['description'] = convert_markdown(lesson['description'],
                                                     inline=True)
        for mat in lesson.get('materials', ()):
            mat['name'] = convert_markdown(mat['name'], inline=True)

    return data


def pathto(name, static=False):
    if static:
        prefix = '_static/'
{'fraction_non_alphanumeric': 0.15980629539951574, 'fraction_numerical': 0.00903954802259887, 'mean_word_length': 4.141908713692946, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1594773', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2112, 'n_words': 423}