<commit_before># coding: utf-8
from shared import BaseClient, authentication_required
from datetime import datetime, timedelta
from tvdb_client.utils import requests_util, utils
from tvdb_client.exceptions import AuthenticationFailedException
import json

__author__ = 'tsantana'


class ApiV2Client(BaseClient):
    """
    This is the python library implementation of the TheTVDB API V2. Details of the APIs is documented in the swagger
    page maintained by TheTVDB that can be found on this address: https://api.thetvdb.com/swagger

    The only APIs not represented by methods in this library are the ones that only returns parameters information of
    the actual API.
    """

    API_BASE_URL = 'https://api.thetvdb.com'
    TOKEN_DURATION_SECONDS = 23 * 3600  # 23 Hours
    TOKEN_MAX_DURATION = 24 * 3600  # 24 Hours

    def __init__(self, username, api_key, account_identifier, language=None):
        self.username = username
        self.api_key = api_key
        self.account_identifier = account_identifier
        self.is_authenticated = False
        self.__token = None
        self.__auth_time = 0
        self.language = language

    def __get_header(self):
        header = dict()
        header['Content-Type'] = 'application/json'

        if self.language:
            header['Accept-Language'] = self.language

        return header

    def __refresh_token(self):
        headers = self.__get_header()
        headers['Authorization'] = 'Bearer %s' % self.__token

        resp = requests_util.run_request('get', self.API_BASE_URL + '/refresh_token', headers=headers)

        if resp.status_code == 200:
            token_resp = json.loads(resp.content)
            self.__token = token_resp['token']<commit_msg>TheTVDB has added an user agent validation for the V2 API usage.<commit_after># coding: utf-8
from shared import BaseClient, authentication_required
from datetime import datetime, timedelta
from tvdb_client.utils import requests_util, utils
from tvdb_client.exceptions import AuthenticationFailedException
import json

__author__ = 'tsantana'


class ApiV2Client(BaseClient):
    """
    This is the python library implementation of the TheTVDB API V2. Details of the APIs is documented in the swagger
    page maintained by TheTVDB that can be found on this address: https://api.thetvdb.com/swagger

    The only APIs not represented by methods in this library are the ones that only returns parameters information of
    the actual API.
    """

    API_BASE_URL = 'https://api.thetvdb.com'
    TOKEN_DURATION_SECONDS = 23 * 3600  # 23 Hours
    TOKEN_MAX_DURATION = 24 * 3600  # 24 Hours

    def __init__(self, username, api_key, account_identifier, language=None):
        self.username = username
        self.api_key = api_key
        self.account_identifier = account_identifier
        self.is_authenticated = False
        self.__token = None
        self.__auth_time = 0
        self.language = language

    def __get_header(self):
        header = dict()
        header['Content-Type'] = 'application/json'
        header['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0'

        if self.language:
            header['Accept-Language'] = self.language

        return header

    def __refresh_token(self):
        headers = self.__get_header()
        headers['Authorization'] = 'Bearer %s' % self.__token

        resp = requests_util.run_request('get', self.API_BASE_URL + '/refresh_token', headers=headers)

        if resp.status_code == 200:
            token_resp = json.loads(resp.content)
            self.__token = token_resp['token']
{'fraction_non_alphanumeric': 0.08134757600657354, 'fraction_numerical': 0.018351136674883594, 'mean_word_length': 3.089585666293393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '6182599', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1023, 'n_words': 313}