<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bottle import response, request

from bson.json_util import dumps

from utils import slugfy


def base():
    response.set_header('charset', 'utf-8')
    response.content_type = 'application/json'


def get(mongodb, collection, slug):
    base()
    if slug:
        data = mongodb[collection].find({'slug': slug})
    else:
        data = mongodb[collection].find()
    response = []
    for d in data:
        del d['_id']
        response.append(d)
    return dumps(response)


def post(mongodb, collection, opt={}):
    base()
    data = request.json
    data['slug'] = slugfy(data['name'])
    data = dict(data.items() + opt.items())
    get = mongodb[collection].find({'slug': data['slug']})
    if get.count() == 0:
        mongodb[collection].insert(data)
        del data['_id']
        return data
    return {'status': 'error', 'message': 'Object exist, please send PUT!'}


def put(mongodb, collection, slug, opt={}):
    base()
    data = request.json
    data['slug'] = slug
    data = dict(data.items() + opt.items())
    get = mongodb[collection].find_one({'slug': slug})
    if get:
        mongodb[collection].update({'slug': slug}, data)
        return data
    return {'status': 'error',
            'message': 'Object not exist, please send POST to create!'}


def delete(mongodb, collection, slug):
    base()
    mongodb[collection].remove({'slug': slug})
    return {'status': 'success'}<commit_msg>add new parans field on base api used to set new key on database<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bottle import response, request

from bson.json_util import dumps

from utils import slugfy


def base():
    response.set_header('charset', 'utf-8')
    response.content_type = 'application/json'


def get(mongodb, collection, slug):
    base()
    if slug:
        data = mongodb[collection].find({'slug': slug})
    else:
        data = mongodb[collection].find()
    response = []
    for d in data:
        del d['_id']
        response.append(d)
    return dumps(response)


def post(mongodb, collection, opt={}, field={'key': 'slug', 'value': 'name'}):
    base()
    data = request.json
    data[field['key']] = slugfy(data[field['value']])
    data = dict(data.items() + opt.items())
    get = mongodb[collection].find({field['key']: data[field['key']]})
    if get.count() == 0:
        mongodb[collection].insert(data)
        del data['_id']
        return data
    return {'status': 'error', 'message': 'Object exist, please send PUT!'}


def put(mongodb, collection, slug, opt={}, field={'key': 'slug'},
        request_json=request.json):
    base()
    data = request_json
    data[field['key']] = slug
    data = dict(data.items() + opt.items())
    get = mongodb[collection].find_one({field['key']: slug})
    if get:
        mongodb[collection].update({field['key']: slug}, data)
        return data
    return {'status': 'error',
            'message': 'Object not exist, please send POST to create!'}


def delete(mongodb, collection, slug, field={"key": "slug"}):
    base()
    mongodb[collection].remove({'slug': slug})
    return {'status': 'success'}
{'fraction_non_alphanumeric': 0.16750156543519099, 'fraction_numerical': 0.001878522229179712, 'mean_word_length': 3.1984231274638635, 'pattern_counts': {'":': 1, '<': 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': '3358602', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1003, 'n_words': 267}