API

Log

class tsstats.log.TimedLog(path, timestamp)
path

Alias for field number 0

timestamp

Alias for field number 1

class tsstats.log.Server(sid, clients)
clients

Alias for field number 1

sid

Alias for field number 0

tsstats.log.parse_logs(log_glob, ident_map=None, online_dc=True)[source]

Parse logs from log_glob

Parameters:
  • log_glob (str) – path to server-logs (supports globbing)
  • ident_map (dict) – identmap used for Client-initializations
Returns:

list of servers

Return type:

[tsstats.log.Server]

Client

class tsstats.client.Client(identifier, nick=None)[source]

Client provides high-level-access to a Teamspeak-Client

__init__(identifier, nick=None)[source]

Initialize a new Client

Parameters:identifier (int or str) – Identifier of the client
connect(timestamp)[source]

Connect client at timestamp

Parameters:timestamp (int) – time of connect
disconnect(timestamp)[source]

Disconnect client at timestamp

Parameters:timestamp (int) – time of disconnect
kick(target)[source]

Let client kick target

Parameters:target (Client) – client to kick
ban(target)[source]

Let client ban target

Parameters:target (Client) – client to ban
class tsstats.client.Clients(ident_map=None, *args, **kwargs)[source]

A high-level-interface to multiple Client-objects

__init__(ident_map=None, *args, **kwargs)[source]

Initialize a new Client-collection

Parameters:ident_map (dict) – Identity-map (see IdentMap)
__iter__()[source]

Yield all Client-objects from the collection

apply_events(events)[source]

Apply events to this Client-collection

Parameters:events (list) – list of events to apply

Template

class tsstats.template.SortedClients(onlinetime, kicks, pkicks, bans, pbans)
bans

Alias for field number 3

kicks

Alias for field number 1

onlinetime

Alias for field number 0

pbans

Alias for field number 4

pkicks

Alias for field number 2

tsstats.template.prepare_clients(clients, onlinetime_threshold=-1)[source]

Prepare clients for rendering

sort them, clean their nick-history and convert onlinetime to string

Parameters:
  • clients (tsstats.client.Clients) – List of clients to prepare
  • onlinetime_threshold – threshold for clients onlinetime
Returns:

clients sorted by onlinetime, kics, pkicks, bans and pbans

Return type:

tsstats.template.SortedClients

tsstats.template.render_servers(servers, output, title='TeamspeakStats', template='index.jinja2', datetime_fmt='%x %X %Z', onlinetime_threshold=-1, lastseen_relative=True)[source]

Render servers

Parameters:
  • servers ([tsstats.log.Server]) – list of servers to render
  • output (str) – path to output-file
  • template_name (str) – path to template-file
  • title (str) – title of the resulting html-document
  • template_path (str) – path to template-file
  • datetime_fmt (str) – custom datetime-format
  • onlinetime_threshold (int) – threshold for clients onlinetime
  • lastseen_relative (bool) – render last seen timestamp relative

Config

tsstats.config.load(path=None)[source]

parse config at config_path

Parameters:config_path (str) – path to config-file
Returns:values of config
Return type:tuple

Exceptions

exception tsstats.exceptions.InvalidConfiguration[source]

The configuration is invalid (either config-file or cli-args)

Utils

tsstats.utils.sort_clients(clients, key_l)[source]

sort clients by key

Parameters:
  • clients (tsstats.client.Clients) – clients to sort
  • key_l (function) – lambda/function returning the value of key for a client
Returns:

sorted clients

Return type:

list

tsstats.utils.seconds_to_text(seconds)[source]

convert seconds to a text-representation

Parameters:seconds (int) – seconds to convert
Returns:seconds as text-representation
Return type:str
tsstats.utils.filter_threshold(clients, threshold)[source]

Filter clients by threshold

Parameters:clients (list) – List of clients as returned by tsstats.utils.sort_clients
Returns:Clients matching given threshold
Return type:list
tsstats.utils.transform_pretty_identmap(pretty_identmap)[source]

Transforms a list of client ID mappings from a more descriptive format to the traditional format of alternative IDs to actual ID.

Parameters:pretty_identmap (list) – ID mapping in “nice” form
Returns:ID mapping in simple key/value pairs
Return type:dict