blob: faef29b2ad6a3ee378d87f5fe4d85b559e247671 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# Copyright 2016 Egor Tensin <Egor.Tensin@gmail.com>
# This file is licensed under the terms of the MIT License.
# See LICENSE.txt for details.
import logging
class Logger:
@staticmethod
def on_initial_status(user):
if user.is_online():
logging.info(Logger._format_user_is_online(user))
else:
logging.info(Logger._format_user_is_offline(user))
logging.info(Logger._format_user_last_seen(user))
@staticmethod
def on_status_update(user):
if user.is_online():
logging.info(Logger._format_user_went_online(user))
else:
logging.info(Logger._format_user_went_offline(user))
logging.info(Logger._format_user_last_seen(user))
@staticmethod
def on_connection_error(e):
#logging.exception(e)
pass
@staticmethod
def _format_user(user):
if user.has_last_name():
return '{} {}'.format(user.get_first_name(), user.get_last_name())
else:
return '{}'.format(user.get_first_name())
@staticmethod
def _format_user_is_online(user):
return '{} is ONLINE.'.format(Logger._format_user(user))
@staticmethod
def _format_user_is_offline(user):
return '{} is OFFLINE.'.format(Logger._format_user(user))
@staticmethod
def _format_user_last_seen(user):
return '{} was last seen at {} using {}.'.format(
Logger._format_user(user),
user.get_last_seen_time_local(),
user.get_last_seen_platform().get_description_for_sentence())
@staticmethod
def _format_user_went_online(user):
return '{} went ONLINE.'.format(Logger._format_user(user))
@staticmethod
def _format_user_went_offline(user):
return '{} went OFFLINE.'.format(Logger._format_user(user))
|