<commit_before># coding: utf-8

import json
import whiskyton.helpers.whisky as whisky
import whiskyton.helpers.sitemap as whiskyton_sitemap
from flask import abort, Blueprint, redirect, render_template, Response, request, send_from_directory
from whiskyton import app, models
from whiskyton.helpers import charts

files_blueprint = Blueprint('files', __name__)


@files_blueprint.route('/charts/<reference_slug>-<whisky_slug>.svg')
def create_chart(reference_slug, whisky_slug):

    # URL check
    slug1 = whisky.slugfy(whisky_slug)
    slug2 = whisky.slugfy(reference_slug)
    if slug1 != whisky_slug or slug2 != reference_slug:
        return redirect('/charts/%s-%s.svg' % (slug1, slug2))

    # get whisky objects form db
    reference_obj = models.Whisky.query.filter_by(slug=reference_slug).first()
    whisky_obj = models.Whisky.query.filter_by(slug=whisky_slug).first()

    # error page if whisky doesn't exist
    if reference_obj is None or whisky_obj is None:
        return abort(404)

    # if file does not exists, create it
    reference = charts.tastes2list(reference_obj)
    comparison = charts.tastes2list(whisky_obj)
    filename = charts.cache_name(reference, comparison, True)
    if not filename.exists():
        charts.create(reference, comparison)

    # return the chart to the user
    return Response(filename.read_file(), mimetype='image/svg+xml')


@files_blueprint.route('/fonts/glyphicons-halflings-regular.<extension>')
def bootstrap_fonts(extension=None):
    path = app.config['BASEDIR'].child('whiskyton', 'bower', 'bootstrap', 'dist', 'fonts')
    filename = 'glyphicons-halflings-regular.{}'.format(extension)
    if path.child(filename).exists():
        return send_from_directory(path, filename)
    else:
        abort(404)


@files_blueprint.route('/whiskyton.json')
def whisky_json():
    whiskies = models.Whisky.query.all()
    distilleries = json.dumps([w.distillery for w in whiskies])
    resp = Response(
        response=distilleries,
        status=200,
        mimetype='application/json')
    return resp


@files_blueprint.route('/robots.txt')
def robots():
    return send_from_directory(app.config['BASEDIR'].child('whiskyton', 'static'), 'robots.txt')


@files_blueprint.route('/favicon.ico')<commit_msg>Fix bootstrap fonts router<commit_after># coding: utf-8

import json
import whiskyton.helpers.whisky as whisky
import whiskyton.helpers.sitemap as whiskyton_sitemap
from flask import abort, Blueprint, redirect, render_template, Response, request, send_from_directory
from whiskyton import app, models
from whiskyton.helpers import charts

files_blueprint = Blueprint('files', __name__)


@files_blueprint.route('/charts/<reference_slug>-<whisky_slug>.svg')
def create_chart(reference_slug, whisky_slug):

    # URL check
    slug1 = whisky.slugfy(whisky_slug)
    slug2 = whisky.slugfy(reference_slug)
    if slug1 != whisky_slug or slug2 != reference_slug:
        return redirect('/charts/%s-%s.svg' % (slug1, slug2))

    # get whisky objects form db
    reference_obj = models.Whisky.query.filter_by(slug=reference_slug).first()
    whisky_obj = models.Whisky.query.filter_by(slug=whisky_slug).first()

    # error page if whisky doesn't exist
    if reference_obj is None or whisky_obj is None:
        return abort(404)

    # if file does not exists, create it
    reference = charts.tastes2list(reference_obj)
    comparison = charts.tastes2list(whisky_obj)
    filename = charts.cache_name(reference, comparison, True)
    if not filename.exists():
        charts.create(reference, comparison)

    # return the chart to the user
    return Response(filename.read_file(), mimetype='image/svg+xml')


@files_blueprint.route('/static/fonts/glyphicons-halflings-regular.<extension>')
def bootstrap_fonts(extension=None):
    path = app.config['BASEDIR'].child('whiskyton', 'bower', 'bootstrap', 'dist', 'fonts')
    filename = 'glyphicons-halflings-regular.{}'.format(extension)
    if path.child(filename).exists():
        return send_from_directory(path, filename)
    else:
        abort(404)


@files_blueprint.route('/whiskyton.json')
def whisky_json():
    whiskies = models.Whisky.query.all()
    distilleries = json.dumps([w.distillery for w in whiskies])
    resp = Response(
        response=distilleries,
        status=200,
        mimetype='application/json')
    return resp


@files_blueprint.route('/robots.txt')
def robots():
    return send_from_directory(app.config['BASEDIR'].child('whiskyton', 'static'), 'robots.txt')


@files_blueprint.route('/favicon.ico')
{'fraction_non_alphanumeric': 0.11835748792270531, 'fraction_numerical': 0.007905138339920948, 'mean_word_length': 4.416171224732461, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, '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': '1659396', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1475, 'n_words': 308}