Commit 9e07d4bc authored by David Huss's avatar David Huss 💬
Browse files

Add --twolines flag

parent 225da055
......@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
import time
import json
import click
......@@ -60,9 +61,10 @@ def main():
@click.option('--presenter/--no-presenter', default=True, show_default=True, help="Hide or show the presenters")
@click.option('--presenter-id/--no-presenter-id', default=False, show_default=True, help="Hide or show the presenter IDs")
@click.option('--short', '-s', is_flag=True, help="Print less")
@click.option('--twolines', '-2', is_flag=True, help="Print essentials on two lines")
@click.option('--all', '-a', 'all_', is_flag=True, help="Print all")
@click.option('--fancy/--no-fancy', default=True, show_default=True, help="Use fancy headers")
def meetings(ctx, short, all_, leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
"""View currently active meetings"""
if short:
leaderboards = False
......@@ -77,8 +79,14 @@ def meetings(ctx, short, all_, leaderboards, participants, presenter, watch, pre
config.filter_endpoints(endpoint)
if watch is not None:
while watch is not None:
if twolines:
meetings_twolines(config, watch, fancy)
else:
list_meetings(config, leaderboards, participants, presenter, presenter_id, meetings, watch, fancy)
time.sleep(watch)
else:
if twolines:
meetings_twolines(config, watch, fancy)
else:
list_meetings(config, leaderboards, participants, presenter, presenter_id, meetings, watch, fancy)
......@@ -122,6 +130,5 @@ def config(ctx, new, edit, path, print_):
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -168,4 +168,65 @@ def list_meetings(config: Config, leaderboards: bool, participants: bool, presen
def meetings_twolines(config: Config, 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, config.path) 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()
for i, endpoint in enumerate(config.endpoints):
meeting = meetings[i]
# Print divider if there is more than one endpoint
if i > 0:
print("="*click.get_terminal_size()[0])
# If there are no meetings, skip to next endpoint
if len(meeting) == 0:
lines = [
"{:^60}".format("bbb there are no meetings currently."),
""
]
# Cut above 60 characters fill empty
lines = ["{:<60}".format(l[:61]) for l in lines]
lines = "\n".join(lines)
print(lines)
continue
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])
avg_s = sum([int(get_duration(m).total_seconds()) for m in meeting])/float(n_running)
avg_s = avg_s/60./60.
if not fancy:
lines = [
"{} rec / ses ppl mod vid mic ear".format(endpoint.name),
"stats {:>2} / {:<2} {:>3} {:>3} {:>3} {:>3} {:>3}"\
.format(n_recording, n_running, n_participants, n_moderator, n_video, n_voice, n_listeners)
]
else:
lines = [
"{}: There are {} people in {} meetings for {:.1f}h on average"\
.format(endpoint.name, n_participants, n_running, avg_s),
"{} webcams and {} microphones are on. {} just listen. {} mods"\
.format(n_video, n_voice, n_listeners, n_moderator)
]
# Cut above 60 characters fill empty
lines = ["{:^60}".format(l[:61]) for l in lines]
lines = "\n".join(lines)
print(lines)
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