def get_random_figshare_dois(year, sample_size, email, query, seed=None):
    if year < 2011:
        return []

    url_template = "http://api.figshare.com/v1/articles/search?search_for=*&from_date={year}-01-01&to_date={year}-12-31&page={page}&has_publisher_id=0"

    # Do an initial query to get the total number of hits
    url = url_template.format(page=1, year=year)
    print url
    r = requests.get(url)
    initial_response = json.loads(r.text)
    print initial_response
    population_size = initial_response["items_found"]
    print "Number of figshare items returned by this query: %i" %population_size
    print "Off to randomly sample %i of them!" %sample_size

    if seed:
        random.seed(seed)
        print "Seed has been set before sampling."

    if sample_size > population_size:
        print "sample size is bigger than population size, so using population size"
        sample_size = population_size
    random_indexes = random.sample(range(1, population_size), sample_size)

    figshare_ids = []
    for random_index in random_indexes:
        figshare_dict = get_nth_figshare_id(url_template, year, random_index)
        doi = figshare_dict["doi"]
        print "figshare_id:" + doi
        figshare_ids.append(doi)
    return figshare_ids
dataset/ETHPy150Open Impactstory/total-impact-core/extras/build_refsets/get_refsets.py/get_random_figshare_dois/original