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

import logging
import requests
from configloader import load_config, get_config
from collections import OrderedDict

class WebApi(object):

    def __init__(self):
        self.session_pool = requests.Session()

    def getApi(self, uri, params={}):
        try:
            uri_params = params.copy()
            uri_params['key'] = get_config().WEBAPI_TOKEN
            data = self.session_pool.get(
                '%s/mod_mu/%s' %
                (get_config().WEBAPI_URL, uri), params=uri_params).json()
            if data['ret'] == 0:
                return []
            return data['data']
        except Exception:
            raise Exception('network issue or server error!')


    def postApi(self, uri, params={}, raw_data={}):
        try:
            uri_params = params.copy()
            uri_params['key'] = get_config().WEBAPI_TOKEN
            data = self.session_pool.post(
                '%s/mod_mu/%s' %
                (get_config().WEBAPI_URL,
                 uri),
                params=uri_params,
                json=raw_data).json()
            if data['ret'] == 0:
                return []
            return data['data']
        except Exception:
            raise Exception('network issue or server error!')<commit_msg>timeout<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

import logging
import requests
from configloader import load_config, get_config
from collections import OrderedDict

class WebApi(object):

    def __init__(self):
        self.session_pool = requests.Session()

    def getApi(self, uri, params={}):
        try:
            uri_params = params.copy()
            uri_params['key'] = get_config().WEBAPI_TOKEN
            data = self.session_pool.get(
                '%s/mod_mu/%s' %
                (get_config().WEBAPI_URL, uri),
                params=uri_params,
                timeout=10).json()
            if data['ret'] == 0:
                logging.error("request %s error!wrong ret!")
                return []
            return data['data']
        except Exception:
            import traceback
            trace = traceback.format_exc()
            logging.error(trace)
            raise Exception('network issue or server error!')


    def postApi(self, uri, params={}, raw_data={}):
        try:
            uri_params = params.copy()
            uri_params['key'] = get_config().WEBAPI_TOKEN
            data = self.session_pool.post(
                '%s/mod_mu/%s' %
                (get_config().WEBAPI_URL,
                 uri),
                params=uri_params,
                json=raw_data,
                timeout=10).json()
            if data['ret'] == 0:
                logging.error("request %s error!wrong ret!")
                return []
            return data['data']
        except Exception:
            import traceback
            trace = traceback.format_exc()
            logging.error(trace)
            raise Exception('network issue or server error!')
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.003304692663582287, 'mean_word_length': 1.7002676181980374, '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': '7101140', 'n_tokens_mistral': 846, 'n_tokens_neox': 814, 'n_words': 183}