import requests
import time


def get_limited(url, params = None, auth = None):
    """ Get a GitHub API response, keeping in mind that we may
        be rate-limited by the abuse system """
    number_of_retries = 0
    resp = requests.get(url, params = params, auth=auth)
    while resp.status_code == 403 and number_of_retries < 20:
        js = resp.json()
        # If abuse-detection kicks in, sleep it off
        if 'You have triggered an abuse' in js['message']:
            time.sleep(5)
            number_of_retries += 1
            resp = requests.get(url, params = params, auth=auth)
        else:
            break
    resp.raise_for_status()
    return resp.json()