import requests
import json


def getReqJSON(url, args={}):
    """Generic function to get json from an api request"""
    if url.endswith("/"):
        url = url[:-1]

    arg_str = ""
    if isinstance(args, dict):
        if len(args) > 0:
            arg_str = "?" + "&".join([str(k) + "=" + str(args[k]) for k in args])
    elif not isinstance(args, list):
        args = [str(args)]

    if len(args) > 0 and isinstance(args, list):
        arg_str = "/" + "/".join(args)

    url = url + arg_str
    r = requests.get(url=url)
    try:
        return r.json()
    except:
        try:
            return json.loads(r.text + "}")  # why not lul (some apis used here need it)
        except:
            return None