#!/bin/python3
# Importing the library
import argparse
import json
from pathlib import Path
import subprocess
import time
from typing import Dict, List

from karanage import (
    KaranageConnection,
    KaranageException,
    KaranageState,
)
import psutil


if __name__ == '__main__':
    # Load arguments:
    parser = argparse.ArgumentParser()
    parser.add_argument("-C", "--connection", type=str, help="json configuration file")
    parser.add_argument("-t", "--topic", type=str, help="Topic of the message")
    parser.add_argument("-s", "--since", type=str, help="Iso date since the value time must be")

    # This element are read from the connection file:
    parser.add_argument("-u", "--url", type=str, help="Base URL of the web service")
    parser.add_argument("-g", "--group", type=str, help="Group the the message")
    parser.add_argument("-T", "--token", type=str, help="Token to access to the server")
    
    args = parser.parse_args()

    connection = KaranageConnection(
        url = args.url,
        group = args.group,
        token = args.token,
        config_file = args.connection
    )
    
    # create the rest interface of karanage
    stateInterface = KaranageState(connection)
    
    data = stateInterface.gets(topic=args.topic, since=args.since)
    print(f"Ret = {json.dumps(data, indent=4)}")

