Esempio n. 1
0
def grab_subscription(api: API) -> Dict:
    """ Displays all of the user's HYP3 subscriptions, the user then selects
        which subscription they would like to access. The function then returns
        that subscription. """

    data = api.get_subscriptions()

    if not data:
        print("This account has no subscriptions.")
        exit()

    for subsciption in data:
        print(f"ID: {subsciption['id']}: {subsciption['name']}")
    print('Pick an id from the list above: ', end='')

    while True:
        try:
            user_input = int(input())
        except ValueError:
            print('Please insert an integer from above: ', end='')
            continue

        for subscription in data:
            if int(subscription['id']) == user_input:
                return subscription
            else:
                continue
        # Prints if the ID wasn't a choice in the users API
        print("That id wasn't an option, please try again: ", end='')
def get_hyp3_subscriptions(hyp3_api_object: API) -> dict:
    """
    Takes a Hyp3 API object and returns a list of enabled associated subscriptions
    Returns None if there are no enabled subscriptions associated with Hyp3 account.
    precondition: must already be logged into hyp3
    """
    assert type(hyp3_api_object) == API, f"Error: get_hyp3_subscriptions was passed a {type(hyp3_api_object)}, not a asf_hyp3.API object"
    try:
        subscriptions = hyp3_api_object.get_subscriptions(enabled=True)
    except Exception:
        raise
    else:
        if not subscriptions:
            print("There are no subscriptions associated with this Hyp3 account.")
        return subscriptions