diff options
Diffstat (limited to 'vk/utils/tracking/db/writer')
-rw-r--r-- | vk/utils/tracking/db/writer/__init__.py | 5 | ||||
-rw-r--r-- | vk/utils/tracking/db/writer/csv.py | 47 | ||||
-rw-r--r-- | vk/utils/tracking/db/writer/log.py | 57 |
3 files changed, 0 insertions, 109 deletions
diff --git a/vk/utils/tracking/db/writer/__init__.py b/vk/utils/tracking/db/writer/__init__.py deleted file mode 100644 index 8eb62e1..0000000 --- a/vk/utils/tracking/db/writer/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright 2016 Egor Tensin <Egor.Tensin@gmail.com> -# This file is licensed under the terms of the MIT License. -# See LICENSE.txt for details. - -__all__ = 'csv', 'log' diff --git a/vk/utils/tracking/db/writer/csv.py b/vk/utils/tracking/db/writer/csv.py deleted file mode 100644 index 8c635b4..0000000 --- a/vk/utils/tracking/db/writer/csv.py +++ /dev/null @@ -1,47 +0,0 @@ -# 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 csv - -from ..record import Record - -class Writer: - def __init__(self, path, mode='w'): - if path is None: - self._fd = None - else: - self._fd = open(path, mode) - self._writer = csv.writer(self._fd, lineterminator='\n') - - def __bool__(self): - return self._fd is not None - - def __enter__(self): - if not self: - return self - self._fd.__enter__() - return self - - def __exit__(self, *args): - if not self: - return - self._fd.__exit__(*args) - - def flush(self): - if not self: - return - self._fd.flush() - - def write_record(self, user): - if not self: - return - self._write_row(self._record_to_row(Record.from_user(user))) - self.flush() - - def _write_row(self, row): - self._writer.writerow(row) - - @staticmethod - def _record_to_row(record): - return [str(record.get_timestamp())] + [str(record[field]) for field in record] diff --git a/vk/utils/tracking/db/writer/log.py b/vk/utils/tracking/db/writer/log.py deleted file mode 100644 index faef29b..0000000 --- a/vk/utils/tracking/db/writer/log.py +++ /dev/null @@ -1,57 +0,0 @@ -# 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)) |