diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-06-17 06:32:46 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-06-17 06:32:46 +0300 |
commit | 5d9f1fcc26d9090e2250fc39543dbff00abf8d3a (patch) | |
tree | e0ab3246951bb1f527ebd0507e864f8f3e7ec27f /vk/user.py | |
parent | make the status logger a database writer (diff) | |
download | vk-scripts-5d9f1fcc26d9090e2250fc39543dbff00abf8d3a.tar.gz vk-scripts-5d9f1fcc26d9090e2250fc39543dbff00abf8d3a.zip |
add basic "online periods" extraction
Diffstat (limited to 'vk/user.py')
-rw-r--r-- | vk/user.py | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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, } |