From 5d9f1fcc26d9090e2250fc39543dbff00abf8d3a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 17 Jun 2016 06:32:46 +0300 Subject: add basic "online periods" extraction --- vk/user.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'vk/user.py') diff --git a/vk/user.py b/vk/user.py index 80702f6..c2ed623 100644 --- a/vk/user.py +++ b/vk/user.py @@ -93,10 +93,10 @@ class LastSeen(MutableMapping): def __delitem__(self, field): del self._fields[field] - def __iter__(self, field): + def __iter__(self): return iter(self._fields) - def __len__(self, field): + def __len__(self): return len(self._fields) @staticmethod @@ -199,9 +199,20 @@ class User(Hashable, MutableMapping): else: raise TypeError() + def _parse_bool(x): + if isinstance(x, str): + if str(True) == x: + return True + elif str(False) == x: + return False + else: + raise ValueError() + else: + return bool(x) + _FIELD_PARSERS = { UserField.UID: int, - UserField.ONLINE: bool, + UserField.ONLINE: _parse_bool, UserField.LAST_SEEN: _parse_last_seen, } -- cgit v1.2.3