diff options
Diffstat (limited to '')
-rw-r--r-- | vk/tracking/db/record.py | 6 | ||||
-rw-r--r-- | vk/tracking/db/timestamp.py | 30 | ||||
-rw-r--r-- | vk/tracking/online_sessions.py | 24 | ||||
-rw-r--r-- | vk/tracking/status_tracker.py | 34 |
4 files changed, 47 insertions, 47 deletions
diff --git a/vk/tracking/db/record.py b/vk/tracking/db/record.py index 6c000ab..c03c3ca 100644 --- a/vk/tracking/db/record.py +++ b/vk/tracking/db/record.py @@ -38,9 +38,9 @@ class Record(MutableMapping): def __setitem__(self, field, value): if field is LastSeenField.TIME: if isinstance(value, str): - value = Timestamp.from_string(value).impl + value = Timestamp.from_string(value).dt elif isinstance(value, Timestamp): - value = value.impl + value = value.dt elif isinstance(value, datetime): pass else: @@ -78,7 +78,7 @@ class Record(MutableMapping): def _update_last_seen_field(self, last_seen, field): if field is LastSeenField.TIME: - last_seen[field] = self[field].impl + last_seen[field] = self[field].dt else: last_seen[field] = self[field] diff --git a/vk/tracking/db/timestamp.py b/vk/tracking/db/timestamp.py index 0881fb3..b2219ca 100644 --- a/vk/tracking/db/timestamp.py +++ b/vk/tracking/db/timestamp.py @@ -11,25 +11,25 @@ class Timestamp: return datetime.utcnow() @staticmethod - def _is_timezone_aware(impl): - return impl.tzinfo is not None and impl.tzinfo.utcoffset(impl) is not None + def _is_timezone_aware(dt): + return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None @staticmethod - def _lose_timezone(impl): - if Timestamp._is_timezone_aware(impl): - return impl.astimezone(timezone.utc).replace(tzinfo=None) - return impl + def _lose_timezone(dt): + if Timestamp._is_timezone_aware(dt): + return dt.astimezone(timezone.utc).replace(tzinfo=None) + return dt - def __init__(self, impl=None): - if impl is None: - impl = self._new() - impl = impl.replace(microsecond=0) - impl = self._lose_timezone(impl) - self.impl = impl + def __init__(self, dt=None): + if dt is None: + dt = self._new() + dt = dt.replace(microsecond=0) + dt = self._lose_timezone(dt) + self.dt = dt @staticmethod - def from_string(src): - return Timestamp(datetime.strptime(src, '%Y-%m-%dT%H:%M:%SZ')) + def from_string(s): + return Timestamp(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')) def __str__(self): - return self.impl.isoformat() + 'Z' + return self.dt.isoformat() + 'Z' diff --git a/vk/tracking/online_sessions.py b/vk/tracking/online_sessions.py index 11d3196..204e1cc 100644 --- a/vk/tracking/online_sessions.py +++ b/vk/tracking/online_sessions.py @@ -99,20 +99,20 @@ class OnlineSessionEnumerator(MutableMapping): return by_hour @staticmethod - def _split_into_days(time_from, time_to): - while time_from.date() != time_to.date(): - next_day = time_from.date() + timedelta(days=1) - yield time_from.date(), next_day - time_from - time_from = next_day - yield time_to.date(), time_to - time_from + def _split_into_days(a, b): + while a.date() != b.date(): + next_day = a.date() + timedelta(days=1) + yield a.date(), next_day - a + a = next_day + yield b.date(), b - a @staticmethod - def _split_into_hours(time_from, time_to): - while time_from.date() != time_to.date() or time_from.hour != time_to.hour: - next_hour = time_from.replace(minute=0, second=0) + timedelta(hours=1) - yield time_from.hour, next_hour - time_from - time_from = next_hour - yield time_to.hour, time_to - time_from + def _split_into_hours(a, b): + while a.date() != b.date() or a.hour != b.hour: + next_hour = a.replace(minute=0, second=0) + timedelta(hours=1) + yield a.hour, next_hour - a + a = next_hour + yield b.hour, b - a def _process_database_record(self, record): return self._close_user_session(record.to_user()) diff --git a/vk/tracking/status_tracker.py b/vk/tracking/status_tracker.py index d52af6a..d47de39 100644 --- a/vk/tracking/status_tracker.py +++ b/vk/tracking/status_tracker.py @@ -27,21 +27,21 @@ class StatusTracker: self.add_status_update_handler(writer.on_status_update) self.add_connection_error_handler(writer.on_connection_error) - def add_initial_status_handler(self, handler): - self._assert_is_callback(handler) - self._on_initial_status.append(handler) + def add_initial_status_handler(self, fn): + self._assert_is_callback(fn) + self._on_initial_status.append(fn) - def add_status_update_handler(self, handler): - self._assert_is_callback(handler) - self._on_status_update.append(handler) + def add_status_update_handler(self, fn): + self._assert_is_callback(fn) + self._on_status_update.append(fn) - def add_connection_error_handler(self, handler): - self._assert_is_callback(handler) - self._on_connection_error.append(handler) + def add_connection_error_handler(self, fn): + self._assert_is_callback(fn) + self._on_connection_error.append(fn) @staticmethod - def _assert_is_callback(handler): - if not isinstance(handler, Callable): + def _assert_is_callback(fn): + if not isinstance(fn, Callable): raise TypeError() _USER_FIELDS = UserField.DOMAIN, UserField.ONLINE, UserField.LAST_SEEN, @@ -50,16 +50,16 @@ class StatusTracker: return {user.get_uid(): user for user in self._api.users_get(uids, self._USER_FIELDS)} def _notify_status(self, user): - for handler in self._on_initial_status: - handler(user) + for fn in self._on_initial_status: + fn(user) def _notify_status_update(self, user): - for handler in self._on_status_update: - handler(user) + for fn in self._on_status_update: + fn(user) def _notify_connection_error(self, e): - for handler in self._on_connection_error: - handler(e) + for fn in self._on_connection_error: + fn(e) def _query_initial_status(self, uids): while True: |