aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/tracking
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-12-23 07:20:36 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-12-23 07:20:36 +0300
commit7b8cc8a9f455eda41b9c7d70f4561a84fcda941e (patch)
treeb9e262e9a1dbb663c3b9f704a9fe4daf54be0ce9 /vk/tracking
parentTravis: online_sessions.sh: refactoring (diff)
downloadvk-scripts-7b8cc8a9f455eda41b9c7d70f4561a84fcda941e.tar.gz
vk-scripts-7b8cc8a9f455eda41b9c7d70f4561a84fcda941e.zip
pylint/pep8 fixes
Diffstat (limited to '')
-rw-r--r--vk/tracking/db/backend/csv.py2
-rw-r--r--vk/tracking/db/backend/log.py1
-rw-r--r--vk/tracking/db/backend/null.py2
-rw-r--r--vk/tracking/db/format.py29
-rw-r--r--vk/tracking/db/io.py8
-rw-r--r--vk/tracking/db/meta.py2
-rw-r--r--vk/tracking/db/record.py1
-rw-r--r--vk/tracking/db/timestamp.py1
-rw-r--r--vk/tracking/online_sessions.py2
-rw-r--r--vk/tracking/status_tracker.py4
10 files changed, 34 insertions, 18 deletions
diff --git a/vk/tracking/db/backend/csv.py b/vk/tracking/db/backend/csv.py
index 4943ff2..43038e4 100644
--- a/vk/tracking/db/backend/csv.py
+++ b/vk/tracking/db/backend/csv.py
@@ -8,6 +8,7 @@ from ..io import FileReaderCSV, FileWriterCSV
from ..record import Record
from ..timestamp import Timestamp
+
class Writer(meta.Writer):
def __init__(self, fd):
self._writer = FileWriterCSV(fd)
@@ -30,6 +31,7 @@ class Writer(meta.Writer):
def _record_to_row(record):
return [str(record.get_timestamp())] + [str(record[field]) for field in record]
+
class Reader(meta.Reader):
def __init__(self, fd):
self._reader = FileReaderCSV(fd)
diff --git a/vk/tracking/db/backend/log.py b/vk/tracking/db/backend/log.py
index 814cabc..d301856 100644
--- a/vk/tracking/db/backend/log.py
+++ b/vk/tracking/db/backend/log.py
@@ -7,6 +7,7 @@ import logging
from .. import meta
+
class Writer(meta.Writer):
def __init__(self, fd):
self._logger = logging.getLogger(__file__)
diff --git a/vk/tracking/db/backend/null.py b/vk/tracking/db/backend/null.py
index 663af10..80a66b4 100644
--- a/vk/tracking/db/backend/null.py
+++ b/vk/tracking/db/backend/null.py
@@ -5,6 +5,7 @@
from .. import meta
+
class Writer(meta.Writer):
def __init__(self):
pass
@@ -18,6 +19,7 @@ class Writer(meta.Writer):
def on_connection_error(self, e):
pass
+
class Reader(meta.Reader):
def __init__(self):
pass
diff --git a/vk/tracking/db/format.py b/vk/tracking/db/format.py
index f9a670c..028d403 100644
--- a/vk/tracking/db/format.py
+++ b/vk/tracking/db/format.py
@@ -8,6 +8,7 @@ import sys
from . import backend, io
+
class Format(Enum):
CSV = 'csv'
LOG = 'log'
@@ -19,22 +20,20 @@ class Format(Enum):
def create_writer(self, fd=sys.stdout):
if self is Format.CSV:
return backend.csv.Writer(fd)
- elif self is Format.LOG:
+ if self is Format.LOG:
return backend.log.Writer(fd)
- elif self is Format.NULL:
+ if self is Format.NULL:
return backend.null.Writer()
- else:
- raise NotImplementedError('unsupported database format: ' + str(self))
+ raise NotImplementedError('unsupported database format: ' + str(self))
def open_output_file(self, path=None):
if self is Format.CSV:
return self._open_output_database_file(path)
- elif self is Format.LOG:
+ if self is Format.LOG:
return self._open_output_log_file(path)
- elif self is Format.NULL:
+ if self is Format.NULL:
return self._open_output_database_file(None)
- else:
- raise NotImplementedError('unsupported database format: ' + str(self))
+ raise NotImplementedError('unsupported database format: ' + str(self))
@staticmethod
def _open_output_log_file(path):
@@ -47,19 +46,17 @@ class Format(Enum):
def create_reader(self, fd=sys.stdin):
if self is Format.CSV:
return backend.csv.Reader(fd)
- elif self is Format.LOG:
+ if self is Format.LOG:
return NotImplementedError('cannot read from a log file')
- elif self is Format.NULL:
+ if self is Format.NULL:
return backend.null.Reader()
- else:
- raise NotImplementedError('unsupported database format: ' + str(self))
+ raise NotImplementedError('unsupported database format: ' + str(self))
def open_input_file(self, path=None):
if self is Format.CSV:
return io.open_input_text_file(path)
- elif self is Format.LOG:
+ if self is Format.LOG:
raise NotImplementedError('cannot read from a log file')
- elif self is Format.NULL:
+ if self is Format.NULL:
return io.open_input_text_file(None)
- else:
- raise NotImplementedError('unsupported database format: ' + str(self))
+ raise NotImplementedError('unsupported database format: ' + str(self))
diff --git a/vk/tracking/db/io.py b/vk/tracking/db/io.py
index 37d9c53..a89865f 100644
--- a/vk/tracking/db/io.py
+++ b/vk/tracking/db/io.py
@@ -7,6 +7,7 @@ from contextlib import contextmanager
import csv
import sys
+
class FileWriterCSV:
def __init__(self, fd=sys.stdout):
self._fd = fd
@@ -14,7 +15,7 @@ class FileWriterCSV:
@staticmethod
def _convert_row_old_python(row):
- if isinstance(row, list) or isinstance(row, tuple):
+ if isinstance(row, (list, tuple)):
return row
return list(row)
@@ -24,6 +25,7 @@ class FileWriterCSV:
self._writer.writerow(row)
self._fd.flush()
+
class FileReaderCSV:
def __init__(self, fd=sys.stdin):
self._reader = csv.reader(fd)
@@ -31,6 +33,7 @@ class FileReaderCSV:
def __iter__(self):
return iter(self._reader)
+
@contextmanager
def _open_file(path=None, default=None, **kwargs):
if path is None:
@@ -39,12 +42,15 @@ def _open_file(path=None, default=None, **kwargs):
with open(path, **kwargs) as fd:
yield fd
+
_DEFAULT_ENCODING = 'utf-8'
+
def open_output_text_file(path=None, mode='w'):
return _open_file(path, default=sys.stdout, mode=mode,
encoding=_DEFAULT_ENCODING)
+
def open_input_text_file(path=None):
return _open_file(path, default=sys.stdin, mode='r',
encoding=_DEFAULT_ENCODING)
diff --git a/vk/tracking/db/meta.py b/vk/tracking/db/meta.py
index 024d9d8..eb15c74 100644
--- a/vk/tracking/db/meta.py
+++ b/vk/tracking/db/meta.py
@@ -6,6 +6,7 @@
import abc
from collections.abc import Iterable
+
class Writer(metaclass=abc.ABCMeta):
@abc.abstractmethod
def on_initial_status(self, user):
@@ -19,6 +20,7 @@ class Writer(metaclass=abc.ABCMeta):
def on_connection_error(self, e):
pass
+
class Reader(Iterable, metaclass=abc.ABCMeta):
@abc.abstractmethod
def __iter__(self):
diff --git a/vk/tracking/db/record.py b/vk/tracking/db/record.py
index dfd47c6..6998238 100644
--- a/vk/tracking/db/record.py
+++ b/vk/tracking/db/record.py
@@ -12,6 +12,7 @@ from vk.user import User, UserField
from .timestamp import Timestamp
+
class Record(MutableMapping):
FIELDS = (
UserField.UID,
diff --git a/vk/tracking/db/timestamp.py b/vk/tracking/db/timestamp.py
index b2219ca..1309797 100644
--- a/vk/tracking/db/timestamp.py
+++ b/vk/tracking/db/timestamp.py
@@ -5,6 +5,7 @@
from datetime import datetime, timezone
+
class Timestamp:
@staticmethod
def _new():
diff --git a/vk/tracking/online_sessions.py b/vk/tracking/online_sessions.py
index 204e1cc..c43e11c 100644
--- a/vk/tracking/online_sessions.py
+++ b/vk/tracking/online_sessions.py
@@ -8,6 +8,7 @@ from collections.abc import MutableMapping
from datetime import timedelta
from enum import Enum
+
class Weekday(Enum):
MONDAY = 0
TUESDAY = 1
@@ -20,6 +21,7 @@ class Weekday(Enum):
def __str__(self):
return self.name[0] + self.name[1:].lower()
+
class OnlineSessionEnumerator(MutableMapping):
def __init__(self, time_from=None, time_to=None):
self._records = {}
diff --git a/vk/tracking/status_tracker.py b/vk/tracking/status_tracker.py
index 30e0f97..b87e059 100644
--- a/vk/tracking/status_tracker.py
+++ b/vk/tracking/status_tracker.py
@@ -11,6 +11,7 @@ import signal
import vk.error
from vk.user import UserField
+
class StatusTracker:
DEFAULT_TIMEOUT = 5
@@ -49,7 +50,8 @@ class StatusTracker:
_USER_FIELDS = UserField.DOMAIN, UserField.ONLINE, UserField.LAST_SEEN,
def _query_status(self, uids):
- user_list = self._api.users_get(uids, self._USER_FIELDS, deactivated_users=False)
+ user_list = self._api.users_get(uids, self._USER_FIELDS,
+ deactivated_users=False)
return {user.get_uid(): user for user in user_list}
def _notify_status(self, user):