aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-09-09 18:43:21 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-09-09 18:43:21 +0300
commit3ab60034bc8a71df3791d8ba32ca46cad120af4c (patch)
tree1fe67f6247a294773ddf2b5627ce4571a4bfae8f
parentadd "service" access_token (diff)
downloadvk-scripts-3ab60034bc8a71df3791d8ba32ca46cad120af4c.tar.gz
vk-scripts-3ab60034bc8a71df3791d8ba32ca46cad120af4c.zip
add show_status.py
-rw-r--r--bin/show_status.py39
-rw-r--r--vk/tracking/status_tracker.py6
2 files changed, 44 insertions, 1 deletions
diff --git a/bin/show_status.py b/bin/show_status.py
new file mode 100644
index 0000000..74e1ac8
--- /dev/null
+++ b/bin/show_status.py
@@ -0,0 +1,39 @@
+# Copyright (c) 2019 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "VK scripts" project.
+# For details, see https://github.com/egor-tensin/vk-scripts.
+# Distributed under the MIT License.
+
+import argparse, sys
+
+from vk.api import API
+from vk.tracking import StatusTracker
+from vk.tracking.db import Format as DatabaseFormat
+
+def _parse_args(args=None):
+ if args is None:
+ args = sys.argv[1:]
+
+ parser = argparse.ArgumentParser(
+ description='Show if people are online/offline.')
+
+ parser.add_argument('uids', metavar='UID', nargs='+',
+ help='user IDs or "screen names"')
+ parser.add_argument('-l', '--log', metavar='PATH', dest='log_path',
+ help='set log file path (standard output by default)')
+
+ return parser.parse_args(args)
+
+def track_status(uids, log_path=None):
+ api = API()
+ tracker = StatusTracker(api)
+
+ with DatabaseFormat.LOG.open_output_file(log_path) as log_fd:
+ log_writer = DatabaseFormat.LOG.create_writer(log_fd)
+ tracker.add_database_writer(log_writer)
+ tracker.query_status(uids)
+
+def main(args=None):
+ track_status(**vars(_parse_args(args)))
+
+if __name__ == '__main__':
+ main()
diff --git a/vk/tracking/status_tracker.py b/vk/tracking/status_tracker.py
index e1a3216..8b90d1c 100644
--- a/vk/tracking/status_tracker.py
+++ b/vk/tracking/status_tracker.py
@@ -85,10 +85,14 @@ class StatusTracker:
old_users[uid] = user
yield user
- def _do_loop(self, uids):
+ def query_status(self, uids):
users = self._query_initial_status(uids)
for user in users.values():
self._notify_status(user)
+ return users
+
+ def _do_loop(self, uids):
+ users = self.query_status(uids)
while True:
updated_users = self._query_status_updates(uids)
for user in self._filter_status_updates(users, updated_users):