from typing import Dict
import requests


def getPeeringDB(ASN: str) -> Dict:
    """Function to connect to peeringDB and fetch results for a given ASN

    Args:
        ASN: ASN to query against PeeringDB's API.

    Returns:
        r.json: a dict containing the results from PeeringDB

    """
    pdb_url = f"https://api.peeringdb.com/api/net?asn__in={ASN}&depth=2"
    print(f"Fetching PeeringDB info for {ASN}")
    r = requests.get(pdb_url)
    if r.status_code != requests.status_codes.codes.ALL_OK:
        print("Got unexpected status code, exiting")
        print("%s - %s" % (r.status_code, r.text))
        exit(1)
    if len(r.json()["data"]) != 1:
        print(
            f"Got unexpected number of replies for {ASN}(Does ASN exist in PeeringDB?). Exiting"
        )
        exit(1)
    return r.json()