def query_api(path, retry=3, limit=None, **kwargs):
    url = GovTrackURL(path=path, **kwargs)
    while True:
        response = json.load(urllib2.urlopen(url.to_string()))
        meta = response['meta']
        objects = response['objects']
        offset = meta['offset']
        limit = limit if limit is not None else meta['total_count']
        for obj in objects:
            offset += 1
            progress = int((float(offset)/limit) * 100)
            obj_url = GovTrackURL(path='%s/%s' % (path, obj['id']))
            # Sometimes we get back a 502 error. If we do, just try getting the
            # object again. Attempt up to the 'retry' limit (default is 3)
            for i in range(retry):
                try:
                    yield json.load(urllib2.urlopen(obj_url.to_string())), progress
                    break
                except urllib2.HTTPError:
                    pass

            # If the limit argument is set, exit after we've reached that limit
            if limit is not None and offset >= limit:
                return

        # Update the current offset value and, if we've retrieved all of the
        # objects available, exit this function
        url.offset = meta['offset'] + meta['limit']
        # if url.offset > meta['total_count']:
        #     return
Save history to file
dataset/ETHPy150Open croach/pydata2013/govtrack.py/query_api--crossover with--dataset/ETHPy150Open DTVD/rainbowstream/rainbowstream/interactive.py/save_history