Commit 66c5eb04 authored by David Huss's avatar David Huss 💬
Browse files

Add naive --watch option

Usage:
```
bbbmon -w 2
```

Note that this uses sleep and sleeps for e.g. 2 seconds inbetween
requests. A more accurate way would probably be to messure the time that
has passed since starting the request and subtracting that from the
interval.
parent 37df7523
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import time
import hashlib
from datetime import datetime, timedelta
import requests
......@@ -177,13 +178,23 @@ def print_header(endpoint_name: str, text: str, fancy=True):
else:
print("[{}] {}".format(endpoint_name, text))
def print_overview(config: Config, leaderboards: bool, participants: bool, presenter: bool, presenter_id: bool, show_meetings: bool, fancy: bool):
def print_overview(config: Config, leaderboards: bool, participants: bool, presenter: bool, presenter_id: bool, show_meetings: bool, watch: int, fancy: bool):
"""
For each endpoint in the configuration get the active meetings and print
out an overview of the current bbb-usage
"""
# Request Meetings from API
meetings = [get_meetings(e.secret, e.url) for e in config.endpoints]
# Clear screen after request is done, and before printing new data to keep
# blinking to a minimum
if watch is not None:
click.clear()
print(watch)
for i, endpoint in enumerate(config.endpoints):
meetings = get_meetings(endpoint.secret, endpoint.url)
meeting = meetings[i]
# Print divider if there is more than one endpoint
if i > 0:
......@@ -192,19 +203,19 @@ def print_overview(config: Config, leaderboards: bool, participants: bool, prese
print()
# If there are no meetings, skip to next endpoint
if len(meetings) == 0:
if len(meeting) == 0:
if show_meetings:
print_header(endpoint.name, "MEETINGS", fancy)
print(" └─── Currently no active meetings.")
continue
n_running = len(meetings)
n_recording = len([m for m in meetings if m["recording"] == "true"])
n_participants = sum([int(m["participantCount"]) for m in meetings])
n_listeners = sum([int(m["listenerCount"]) for m in meetings])
n_voice = sum([int(m["voiceParticipantCount"]) for m in meetings])
n_video = sum([int(m["videoCount"]) for m in meetings])
n_moderator = sum([int(m["moderatorCount"]) for m in meetings])
n_running = len(meeting)
n_recording = len([m for m in meeting if m["recording"] == "true"])
n_participants = sum([int(m["participantCount"]) for m in meeting])
n_listeners = sum([int(m["listenerCount"]) for m in meeting])
n_voice = sum([int(m["voiceParticipantCount"]) for m in meeting])
n_video = sum([int(m["videoCount"]) for m in meeting])
n_moderator = sum([int(m["moderatorCount"]) for m in meeting])
if show_meetings:
print_header(endpoint.name, "MEETINGS", fancy)
......@@ -222,13 +233,13 @@ def print_overview(config: Config, leaderboards: bool, participants: bool, prese
if leaderboards:
print()
print_leaderboard(meetings, "participantCount", endpoint.name, presenter, presenter_id, fancy)
print_leaderboard(meeting, "participantCount", endpoint.name, presenter, presenter_id, fancy)
print()
print_leaderboard(meetings, "videoCount", endpoint.name, presenter, presenter_id, fancy)
print_leaderboard(meeting, "videoCount", endpoint.name, presenter, presenter_id, fancy)
print()
print_leaderboard(meetings, "voiceParticipantCount", endpoint.name, presenter, presenter_id, fancy)
print_leaderboard(meeting, "voiceParticipantCount", endpoint.name, presenter, presenter_id, fancy)
print()
print_duration_leaderboard(meetings, endpoint.name, presenter, presenter_id, fancy)
print_duration_leaderboard(meeting, endpoint.name, presenter, presenter_id, fancy)
def init_config() -> Optional[Config]:
......@@ -261,16 +272,22 @@ def init_config() -> Optional[Config]:
@click.command()
@click.option('--endpoint', '-e', multiple=True, help="Filter by one or more endpoints as named in the user configuration (e.g. [servername]). Order is respected.")
@click.option('--watch', '-w', help="Run repeatedly with the given interval in seconds", type=click.IntRange(2, 2147483647, clamp=True))
@click.option('--leaderboards/--no-leaderboards', default=True, show_default=True, help="Hide or show the meeting leaderboards")
@click.option('--participants/--no-participants', default=True, show_default=True, help="Hide or show the participants")
@click.option('--meetings/--no-meetings', default=True, show_default=True, help="Hide or show the meetings")
@click.option('--presenter/--no-presenter', default=True, show_default=True, help="Hide or show the presenters")
@click.option('--presenter-id/--no-presenter-id', default=True, show_default=True, help="Hide or show the presenter IDs")
@click.option('--fancy/--no-fancy', default=True, show_default=True, help="Use fancy headers")
def main(leaderboards, participants, presenter, presenter_id, meetings, endpoint, fancy):
def main(leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
config = init_config()
config.filter_endpoints(endpoint)
print_overview(config, leaderboards, participants, presenter, presenter_id, meetings, fancy)
if watch is not None:
while watch is not None:
print_overview(config, leaderboards, participants, presenter, presenter_id, meetings, watch, fancy)
time.sleep(watch)
else:
print_overview(config, leaderboards, participants, presenter, presenter_id, meetings, watch, fancy)
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment