aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/bin/show_status.py
blob: 74e1ac81c6aff0ca14212543f7c0667a48612621 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()