Skip to content
Snippets Groups Projects
Commit 0c7c0153 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Add json command

parent 416672c4
Branches
Tags
No related merge requests found
......@@ -141,6 +141,25 @@ def config(ctx, userconfig, watch, new, edit, path, print_):
click.echo(ctx.get_help())
@main.command(context_settings=CONTEXT_SETTINGS)
@click.pass_context
@click.option('--watch', '-w', help="Run repeatedly with the given interval in seconds", type=click.IntRange(2, 2147483647, clamp=True))
@click.option('--compact/--pretty', '-c/-p', default=False, show_default=True, help="Print pretty and indented json or compact")
@click.option('--userconfig', '-u', is_flag=True, help="Use user config even if on server")
@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.")
def json(ctx, userconfig, watch, endpoint, compact):
"""Print json"""
config = init_config(userconfig)
config.filter_endpoints(endpoint)
if not config.endpoints:
exit()
if watch is not None:
while watch is not None:
print(format_json(config, watch, compact))
time.sleep(watch)
else:
print(format_json(config, watch, compact))
......
......@@ -4,6 +4,7 @@
import time
import subprocess
import hashlib
import json
from datetime import datetime, timedelta
import requests
from xml.etree import cElementTree as ElementTree
......@@ -269,3 +270,18 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
lines = ["{:^60}".format(l[:61]) for l in lines]
lines = "\n".join(lines)
print(lines)
def format_json(config: Config, watch: bool, compact: bool) -> str:
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()
if compact:
return str(json.dumps(meetings))
else:
return str(json.dumps(meetings, indent=4))
......@@ -7,6 +7,7 @@ from typing import NewType, Optional, Tuple, Iterable, List
from bbbmon.xmldict import XmlListConfig, XmlDictConfig
import bbbmon.meetings
from bbbmon.configuration import Config
......
[tool.poetry]
name = "bbbmon"
version = "0.1.22"
version = "0.1.23"
description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment