<commit_before># -*- coding: utf-8 -*-
"""
    API Client for Goo labs API
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :author: tell-k <<EMAIL>>
    :copyright: tell-k. All Rights Reserved.
"""
from __future__ import division, print_function, absolute_import, unicode_literals  # NOQA

import json
import requests


class GoolabsAPI(object):

    BASE_API_URL = "https://labs.goo.ne.jp/api/{}"
    API_NAMES = ['morph', "similarity", "hiragana", "entity"]

    def __init__(self, app_id, timeout=None, headers={}):
        self._app_id = app_id
        self._timeout = timeout or 30
        self._headers = {'content-type': 'application/json'}
        self.response = None
        if headers:
            self._headers.update(headers)

    def __getattr__(self, func):
        if func not in self.API_NAMES:
            raise AttributeError(
                "Can't access or call this attribute '{0}'".format(func))

        req_url = self.BASE_API_URL.format(func)

        def inner_func(**kwargs):
            payload = {k: v for k, v in kwargs.items() if v}
            payload.update({"app_id": self._app_id})
            self.response = requests.post(
                req_url,
                data=json.dumps(payload),
                timeout=self._timeout,
                headers=self._headers
            )
            self.response.raise_for_status()
            return self.response.json()
        return inner_func<commit_msg>remove dict comprehension. for python 2.6<commit_after># -*- coding: utf-8 -*-
"""
    API Client for Goo labs API
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :author: tell-k <<EMAIL>>
    :copyright: tell-k. All Rights Reserved.
"""
from __future__ import division, print_function, absolute_import, unicode_literals  # NOQA

import json
import requests


class GoolabsAPI(object):

    BASE_API_URL = "https://labs.goo.ne.jp/api/{}"
    API_NAMES = ['morph', "similarity", "hiragana", "entity"]

    def __init__(self, app_id, timeout=None, headers={}):
        self._app_id = app_id
        self._timeout = timeout or 30
        self._headers = {'content-type': 'application/json'}
        self.response = None
        if headers:
            self._headers.update(headers)

    def __getattr__(self, func):
        if func not in self.API_NAMES:
            raise AttributeError(
                "Can't access or call this attribute '{0}'".format(func))

        req_url = self.BASE_API_URL.format(func)

        def inner_func(**kwargs):
            payload = dict([(k, v) for k, v in kwargs.items() if v])
            payload.update({"app_id": self._app_id})
            self.response = requests.post(
                req_url,
                data=json.dumps(payload),
                timeout=self._timeout,
                headers=self._headers
            )
            self.response.raise_for_status()
            return self.response.json()
        return inner_func
{'fraction_non_alphanumeric': 0.13457556935817805, 'fraction_numerical': 0.003450655624568668, 'mean_word_length': 2.221111111111111, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3258683', 'n_tokens_mistral': 882, 'n_tokens_neox': 831, 'n_words': 206}