Skip to content
client.py 865 B
Newer Older
Antoine Millet's avatar
Antoine Millet committed
#!/usr/bin/env python
#coding=utf8

Antoine Millet's avatar
Antoine Millet committed
from datetime import datetime

Antoine Millet's avatar
Antoine Millet committed
class CCClient(object):
    '''
    Represent a single client connected to the server.
    '''

    def __init__(self, login, role, server, connection):

        # The login of the client:
Antoine Millet's avatar
Antoine Millet committed

        # The role of the client:
Antoine Millet's avatar
Antoine Millet committed

        # The server binded to this client:
Antoine Millet's avatar
Antoine Millet committed

        # The connection of the client (public attribute):
        self.connection = connection

Antoine Millet's avatar
Antoine Millet committed
        # The date of connection of the client:
        self._connection_date = datetime.now()
Antoine Millet's avatar
Antoine Millet committed

Antoine Millet's avatar
Antoine Millet committed
    def get_uptime(self):
Antoine Millet's avatar
Antoine Millet committed
        '''
Antoine Millet's avatar
Antoine Millet committed
        Get the uptime of the client connection in seconds.
Antoine Millet's avatar
Antoine Millet committed

Antoine Millet's avatar
Antoine Millet committed
        :return: uptime of the client
        '''
        
        dt = datetime.now() - self._connection_date
        return dt.seconds + dt.days * 86400