Top

tvdbsimple.updates module

This module implements the Updates functionality of TheTVDb API. Allows to retrieve updated series in a timespan.

See Updates API section

# -*- coding: utf-8 -*-

"""
This module implements the Updates functionality of TheTVDb API.
Allows to retrieve updated series in a timespan.

See [Updates API section](https://api.thetvdb.com/swagger#!/Updates)
"""

from .base import TVDB

class Updates(TVDB):
    """
    Updates class to retrieve updated series in a timespan.
    Requires `fromTime` that is the starting date of the updates.
    """
    _BASE_PATH = 'updated'
    _URLS = {
        'query': '/query',
        'params': '/query/params'
    }

    def __init__(self, fromTime, toTime='', language=''):
        """
        Initialize the Updates class.
        `fromTime` is the epoch time to start your date range to search for.
        You can set `toTime` to set the epoch time to end your date range. 
        Must be one week from `fromTime`.
        You can also set `language` with a language id to get the result 
        in the specific language.
        """
        self._FILTERS = {}
        self.update_filters(fromTime, toTime, language)

    def update_filters(self, fromTime='', toTime='', language=''):
        """
        Updates the filters for the updates class.

        `fromTime` is the epoch time to start your date range to search for.
        You can set `toTime` to set the epoch time to end your date range. 
        Must be one week from `fromTime`.
        You can also set `language` with a language id to get the result 
        in the specific language.
        """
        if fromTime:
            self._FILTERS['fromTime'] = fromTime
        if fromTime:
            self._FILTERS['toTime'] = toTime
        if language:
            self._set_language(language)

    def series(self):
        """
        Get the series updated in the set time span (maximom one week from fromTime).

        Returns a list of series updated in the timespan with basic info
        """
        path = self._get_path('query')
        
        response = self._GET(path, params=self._FILTERS)
        self._set_attrs_to_values({'series': response})
        return response

    def update_params(self):
        """
        Get the filters available for the updated api.

        Returns a list of filters available for updates.
        """
        path = self._get_path('update_params')
        
        response = self._GET(path)
        self._set_attrs_to_values({'update_params': response})
        return response

Classes

class Updates

Updates class to retrieve updated series in a timespan. Requires fromTime that is the starting date of the updates.

class Updates(TVDB):
    """
    Updates class to retrieve updated series in a timespan.
    Requires `fromTime` that is the starting date of the updates.
    """
    _BASE_PATH = 'updated'
    _URLS = {
        'query': '/query',
        'params': '/query/params'
    }

    def __init__(self, fromTime, toTime='', language=''):
        """
        Initialize the Updates class.
        `fromTime` is the epoch time to start your date range to search for.
        You can set `toTime` to set the epoch time to end your date range. 
        Must be one week from `fromTime`.
        You can also set `language` with a language id to get the result 
        in the specific language.
        """
        self._FILTERS = {}
        self.update_filters(fromTime, toTime, language)

    def update_filters(self, fromTime='', toTime='', language=''):
        """
        Updates the filters for the updates class.

        `fromTime` is the epoch time to start your date range to search for.
        You can set `toTime` to set the epoch time to end your date range. 
        Must be one week from `fromTime`.
        You can also set `language` with a language id to get the result 
        in the specific language.
        """
        if fromTime:
            self._FILTERS['fromTime'] = fromTime
        if fromTime:
            self._FILTERS['toTime'] = toTime
        if language:
            self._set_language(language)

    def series(self):
        """
        Get the series updated in the set time span (maximom one week from fromTime).

        Returns a list of series updated in the timespan with basic info
        """
        path = self._get_path('query')
        
        response = self._GET(path, params=self._FILTERS)
        self._set_attrs_to_values({'series': response})
        return response

    def update_params(self):
        """
        Get the filters available for the updated api.

        Returns a list of filters available for updates.
        """
        path = self._get_path('update_params')
        
        response = self._GET(path)
        self._set_attrs_to_values({'update_params': response})
        return response

Ancestors (in MRO)

  • Updates
  • tvdbsimple.base.TVDB
  • builtins.object

Static methods

def __init__(

self, fromTime, toTime='', language='')

Initialize the Updates class. fromTime is the epoch time to start your date range to search for. You can set toTime to set the epoch time to end your date range. Must be one week from fromTime. You can also set language with a language id to get the result in the specific language.

def __init__(self, fromTime, toTime='', language=''):
    """
    Initialize the Updates class.
    `fromTime` is the epoch time to start your date range to search for.
    You can set `toTime` to set the epoch time to end your date range. 
    Must be one week from `fromTime`.
    You can also set `language` with a language id to get the result 
    in the specific language.
    """
    self._FILTERS = {}
    self.update_filters(fromTime, toTime, language)

def get_token(

self, forceNew=False)

Get the existing token or creates it if it doesn't exist. Returns the API token.

If forceNew is true the function will do a new login to retrieve the token.

def get_token(self, forceNew=False):
    """
    Get the existing token or creates it if it doesn't exist.
    Returns the API token.
    If `forceNew` is true  the function will do a new login to retrieve the token.
    """
    from . import KEYS
    if not KEYS.API_TOKEN or forceNew:
        if not KEYS.API_KEY:
            raise APIKeyError
        if hasattr(self,"USER") and hasattr(self,"USER_KEY"):
            data = {"apikey": KEYS.API_KEY, "username": self.USER, "userkey": self.USER_KEY}
        else:
            data={"apikey": KEYS.API_KEY}
        response = requests.request(
                'POST', self._get_complete_url('login'), 
                data=json.dumps(data), 
                headers=self._headers)
        if response.status_code == 200:
            KEYS.API_TOKEN = response.json()['token']
        else:
            error = "Unknown error while authenticating. Check your api key or your user/userkey"
            try:
                error = response.json()['error']
            except:
                pass
            raise AuthenticationError(error)
    return KEYS.API_TOKEN

def refresh_token(

self)

Refresh the current token set in the module.

Returns the new obtained valid token for the API.

def refresh_token(self):
    """
    Refresh the current token set in the module.
    Returns the new obtained valid token for the API.
    """
    self._set_token_header()
    response = requests.request(
        'GET', self._get_complete_url('refresh_token'),
        headers=self._headers)
    response.raise_for_status()
    jsn = response.json()
    if 'token' in jsn:
        from . import KEYS
        KEYS.API_TOKEN = jsn['token']
        return KEYS.API_TOKEN
    return ''

def series(

self)

Get the series updated in the set time span (maximom one week from fromTime).

Returns a list of series updated in the timespan with basic info

def series(self):
    """
    Get the series updated in the set time span (maximom one week from fromTime).
    Returns a list of series updated in the timespan with basic info
    """
    path = self._get_path('query')
    
    response = self._GET(path, params=self._FILTERS)
    self._set_attrs_to_values({'series': response})
    return response

def update_filters(

self, fromTime='', toTime='', language='')

Updates the filters for the updates class.

fromTime is the epoch time to start your date range to search for. You can set toTime to set the epoch time to end your date range. Must be one week from fromTime. You can also set language with a language id to get the result in the specific language.

def update_filters(self, fromTime='', toTime='', language=''):
    """
    Updates the filters for the updates class.
    `fromTime` is the epoch time to start your date range to search for.
    You can set `toTime` to set the epoch time to end your date range. 
    Must be one week from `fromTime`.
    You can also set `language` with a language id to get the result 
    in the specific language.
    """
    if fromTime:
        self._FILTERS['fromTime'] = fromTime
    if fromTime:
        self._FILTERS['toTime'] = toTime
    if language:
        self._set_language(language)

def update_params(

self)

Get the filters available for the updated api.

Returns a list of filters available for updates.

def update_params(self):
    """
    Get the filters available for the updated api.
    Returns a list of filters available for updates.
    """
    path = self._get_path('update_params')
    
    response = self._GET(path)
    self._set_attrs_to_values({'update_params': response})
    return response