<commit_before>#!/usr/bin/python
# coding=utf-8

import falcon
import resources

from catcher import models
from catcher import errors
from catcher import middleware

'''
falcon.API instances are callable WSGI apps

Each component’s process_request, process_resource, and process_response
methods are executed hierarchically, as a stack, following the ordering of the list
passed via the middleware kwarg of falcon.API.
'''
api = falcon.API(middleware=[
    middleware.PeeweeConnection(),
    # middleware.Authorization(),
    middleware.RequireJSON(),
    middleware.JSONTranslator(),
])

# resources are represented by long-lived class instances
api.add_route('/club/{id}', resources.Club(models.Club, ['shortcut', 'city', 'country']))
api.add_route('/clubs', resources.Clubs(models.Club))

api.add_route('/player/{id}', resources.Player(models.Player, ['firstname', 'lastname', 'nickname', 'number', 'ranking']))
api.add_route('/players', resources.Players(models.Player))

api.add_route('/division/{id}', resources.Division(models.Division, ['division']))
api.add_route('/divisions', resources.Divisions(models.Division))

api.add_route('/team/{id}', resources.Division(models.Team, ['divisionId', 'degree']))
api.add_route('/teams', resources.Divisions(models.Team))


api.add_error_handler(Exception, errors.InternalServerError)
api.add_error_handler(TypeError, errors.BadRequest)
api.add_error_handler(KeyError, errors.BadRequest)
api.add_error_handler(models.MySQLModel.DoesNotExist, errors.NotFound)
api.add_error_handler(AttributeError, errors.BadRequest)<commit_msg>logging sql queries<commit_after>#!/usr/bin/python
# coding=utf-8

import falcon
import resources

from catcher import models
from catcher import errors
from catcher import middleware

# print all queries to stderr
import logging
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())

'''
falcon.API instances are callable WSGI apps

Each component’s process_request, process_resource, and process_response
methods are executed hierarchically, as a stack, following the ordering of the list
passed via the middleware kwarg of falcon.API.
'''
api = falcon.API(middleware=[
    middleware.PeeweeConnection(),
    # middleware.Authorization(),
    middleware.RequireJSON(),
    middleware.JSONTranslator(),
])

# resources are represented by long-lived class instances
api.add_route('/club/{id}', r.Club(m.Club,['shortcut', 'city', 'country']))
api.add_route('/clubs', r.Clubs(m.Club))

api.add_route('/player/{id}', r.Player(m.Player,
    ['firstname', 'lastname', 'nickname', 'number', 'ranking']))
api.add_route('/players', r.Players(m.Player))

api.add_route('/division/{id}', r.Division(m.Division, ['division']))
api.add_route('/divisions', r.Divisions(m.Division))

api.add_route('/team/{id}', r.Team(m.Team, ['divisionId', 'degree']))
api.add_route('/teams', r.Teams(m.Team))

# TODO: dodelat
api.add_route('/tournament/{id}', r.Tournament(m.Tournament, []))
api.add_route('/tournaments', r.Tournaments(m.Tournament))
api.add_route('/createTournament', r.CreateTournament())

# errors
api.add_error_handler(Exception, errors.InternalServerError)
api.add_error_handler(TypeError, errors.BadRequest)
api.add_error_handler(KeyError, errors.BadRequest)
api.add_error_handler(ValueError, errors.BadRequest)
api.add_error_handler(m.MySQLModel.DoesNotExist, errors.NotFound)
api.add_error_handler(AttributeError, errors.BadRequest)
{'fraction_non_alphanumeric': 0.14467224949465782, 'fraction_numerical': 0.0005775339301183945, 'mean_word_length': 6.890660592255125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3578867', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1081, 'n_words': 222}