def get_nth_figshare_id(url_template, year, n):
    (page_minus_one, offset) = divmod(n, 10)  #figshare api always has 10 things on a page
    url = url_template.format(page=page_minus_one+1, year=year)
    print url
    r = requests.get(url, timeout=10)    
    response = json.loads(r.text)
    try:
        items = response["items"]
        item = items[offset]
        doi = item["DOI"]
        year_of_item = item["published_date"][-4:]
    except (AttributeError):
        print "no doi found ", item
        doi = None
    except __HOLE__:
        print response
        # try the next page, as a workaround
        return get_nth_figshare_id(url_template, year, n+10)

    doi = doi.replace("http://dx.doi.org/", "")
    return({"doi":doi, "year":year_of_item})
dataset/ETHPy150Open Impactstory/total-impact-core/extras/build_refsets/get_refsets.py/get_nth_figshare_id