Commit 0c7c0153 authored by David Huss's avatar David Huss 💬
Browse files

Add json command

parent 416672c4
......@@ -141,6 +141,25 @@ def config(ctx, userconfig, watch, new, edit, path, print_):
@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)
if not config.endpoints:
if watch is not None:
while watch is not None:
print(format_json(config, watch, compact))
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)
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:
if compact:
return str(json.dumps(meetings))
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
name = "bbbmon"
version = "0.1.22"
version = "0.1.23"
description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <>"]
maintainers = ["David Huss <>"]
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