diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-03 21:24:16 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-03 21:24:16 +0300 |
commit | 9a724815823e034e384f7a0d2de946ef6e090487 (patch) | |
tree | b030ade43356b7ce50b2a1c50a2e6f940d584b94 /vk/tracking/show_status.py | |
parent | README: fix badge link (diff) | |
download | vk-scripts-9a724815823e034e384f7a0d2de946ef6e090487.tar.gz vk-scripts-9a724815823e034e384f7a0d2de946ef6e090487.zip |
move scripts from bin/ to vk/
This is done in preparation to moving to PyPI. TODO:
* update docs,
* merge/rename some scripts.
Diffstat (limited to 'vk/tracking/show_status.py')
-rw-r--r-- | vk/tracking/show_status.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vk/tracking/show_status.py b/vk/tracking/show_status.py new file mode 100644 index 0000000..cf59280 --- /dev/null +++ b/vk/tracking/show_status.py @@ -0,0 +1,44 @@ +# 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 +import 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() |