<commit_before># coding: utf-8

import json
import urlparse

from pyramid.view import view_config
from pyramid.response import Response
from pyramid.httpexceptions import HTTPBadRequest
from pyramid.settings import asbool, aslist
from pylibmc.test import make_test_client, NotAliveError

from icontroller import query_by_pid, query_by_doi, query_by_meta


@view_config(route_name='index', request_method='GET')
def index(request):
    return Response('Cited by SciELO API')


@view_config(route_name='stats', request_method='GET', renderer='jsonp')
def stats(request):
    memcacheds = {}

    mems_addr = aslist(
        request.registry.settings.get('memcached_arguments_url', None))

    for mem in mems_addr:

        addr, port = mem.split(':')

        try:
            alive = bool(make_test_client(host=addr, port=port))
            memcacheds[mem] = alive
        except NotAliveError:
            memcacheds[mem] = False

    return {'health': {'is_alive_es_cluster': request.index._ping(),
            'is_alive_memcached': memcacheds}}


@view_config(route_name='citedby_pid', request_method='GET', renderer='jsonp')
def citedby_pid(request):

    if 'q' not in request.GET:
        raise HTTPBadRequest("parameter 'q' is required")

    if 'metaonly' in request.GET:
        if not request.GET.get('metaonly') in ['true', 'false']:
            raise HTTPBadRequest("parameter 'metaonly' must be 'true' or 'false'")

    metaonly = asbool(request.GET.get('metaonly'))

    articles = query_by_pid(request.GET.get('q'), metaonly)

    return articles


@view_config(route_name='citedby_doi', request_method='GET', renderer='jsonp')
def citedby_doi(request):

    if 'q' not in request.GET:
        raise HTTPBadRequest("parameter 'q' is required")

    if 'metaonly' in request.GET:
        if not request.GET.get('metaonly') in ['true', 'false']:
            raise HTTPBadRequest("parameter 'metaonly' must be 'true' or 'false'")

    metaonly = asbool(request.GET.get('metaonly'))

    articles = query_by_doi(request.GET.get('q'), metaonly)

    return articles


@view_config(route_name='citedby_meta', request_method='GET', renderer='jsonp')
def citedby_meta(request):

    if 'title' not in request.GET:
        raise HTTPBadRequest("at least the parameter 'title' is required")

    if 'metaonly' in request.GET:
        if not request.GET.get('metaonly') in ['true', 'false']:
            raise HTTPBadRequest("parameter 'metaonly' must be 'true' or 'false'")

    metaonly = asbool(request.GET.get('metaonly'))

    articles = query_by_meta(title=request.GET.get('title', ''),
                             author_surname=request.GET.get('author', ''),
                             year=request.GET.get('year', ''),
                             metaonly=metaonly)
    return articles<commit_msg>Alterado o acesso a view function citedby_meta utilizando args<commit_after># coding: utf-8

import json
import urlparse

from pyramid.view import view_config
from pyramid.response import Response
from pyramid.httpexceptions import HTTPBadRequest
from pyramid.settings import asbool, aslist
from pylibmc.test import make_test_client, NotAliveError

from icontroller import query_by_pid, query_by_doi, query_by_meta


@view_config(route_name='index', request_method='GET')
def index(request):
    return Response('Cited by SciELO API')


@view_config(route_name='stats', request_method='GET', renderer='jsonp')
def stats(request):
    memcacheds = {}

    mems_addr = aslist(
        request.registry.settings.get('memcached_arguments_url', None))

    for mem in mems_addr:

        addr, port = mem.split(':')

        try:
            alive = bool(make_test_client(host=addr, port=port))
            memcacheds[mem] = alive
        except NotAliveError:
            memcacheds[mem] = False

    return {'health': {'is_alive_es_cluster': request.index._ping(),
            'is_alive_memcached': memcacheds}}


@view_config(route_name='citedby_pid', request_method='GET', renderer='jsonp')
def citedby_pid(request):

    if 'q' not in request.GET:
        raise HTTPBadRequest("parameter 'q' is required")

    if 'metaonly' in request.GET:
        if not request.GET.get('metaonly') in ['true', 'false']:
            raise HTTPBadRequest("parameter 'metaonly' must be 'true' or 'false'")

    metaonly = asbool(request.GET.get('metaonly'))

    articles = query_by_pid(request.GET.get('q'), metaonly)

    return articles


@view_config(route_name='citedby_doi', request_method='GET', renderer='jsonp')
def citedby_doi(request):

    if 'q' not in request.GET:
        raise HTTPBadRequest("parameter 'q' is required")

    if 'metaonly' in request.GET:
        if not request.GET.get('metaonly') in ['true', 'false']:
            raise HTTPBadRequest("parameter 'metaonly' must be 'true' or 'false'")

    metaonly = asbool(request.GET.get('metaonly'))

    articles = query_by_doi(request.GET.get('q'), metaonly)

    return articles


@view_config(route_name='citedby_meta', request_method='GET', renderer='jsonp')
def citedby_meta(request):

    if 'title' not in request.GET:
        raise HTTPBadRequest("at least the parameter 'title' is required")

    if 'metaonly' in request.GET:
        if not request.GET.get('metaonly') in ['true', 'false']:
            raise HTTPBadRequest("parameter 'metaonly' must be 'true' or 'false'")

    metaonly = asbool(request.GET.get('metaonly'))

    articles = query_by_meta(request.GET.get('title', ''),
                             request.GET.get('author', ''),
                             request.GET.get('year', ''),
                             metaonly)
    return articles
{'fraction_non_alphanumeric': 0.1251329315845445, 'fraction_numerical': 0.0003544842254519674, 'mean_word_length': 3.5180144115292236, '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': '5129595', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1703, 'n_words': 411}