<s> import re <EOL> import random <EOL> import json <EOL> import requests <EOL> def make_collection ( api_url , namespace , nids , title , refset_metadata ) : <EOL> aliases = [ ( namespace , nid ) for nid in nids ] <EOL> url = api_url + "<STR_LIT>" <EOL> resp = requests . post ( <EOL> url , <EOL> data = json . dumps ( { <EOL> "<STR_LIT>" : aliases , <EOL> "<STR_LIT:title>" : title , <EOL> "<STR_LIT>" : refset_metadata <EOL> } ) , <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> ) <EOL> collection_id = json . loads ( resp . text ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> return collection_id <EOL> filename = "<STR_LIT>" <EOL> contents = open ( filename , "<STR_LIT:r>" ) . read ( ) <EOL> doi_pattern = re . compile ( "<STR_LIT>" ) <EOL> all_dois = doi_pattern . findall ( contents ) <EOL> year_pattern = re . compile ( "<STR_LIT>" ) <EOL> all_years = year_pattern . findall ( contents ) <EOL> doi_years = zip ( all_dois , all_years ) <EOL> title_template = "<STR_LIT>" <EOL> api_url = "<STR_LIT>" <EOL> for refset_year in range ( <NUM_LIT> , <NUM_LIT> ) : <EOL> print refset_year <EOL> dois = [ doi for ( doi , year ) in doi_years if year == unicode ( refset_year ) ] <EOL> print len ( dois ) <EOL> seed = <NUM_LIT> <EOL> random . seed ( seed ) <EOL> sample_size = <NUM_LIT:100> <EOL> selected = random . sample ( dois , min ( sample_size , len ( dois ) ) ) <EOL> refset_metadata = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : <NUM_LIT:0.1> , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : refset_year , <EOL> "<STR_LIT>" : seed , <EOL> "<STR_LIT>" : sample_size <EOL> } <EOL> title = title_template . format ( ** refset_metadata ) <EOL> collection_id = make_collection ( api_url , "<STR_LIT>" , selected , title , refset_metadata ) <EOL> print collection_id </s>
