<s> __author__ = '<STR_LIT>' <EOL> import requests <EOL> import csv <EOL> import random <EOL> def get_slugs ( ) : <EOL> url = "<STR_LIT>" <EOL> rows = requests . get ( url ) . json ( ) [ "<STR_LIT>" ] <EOL> slugs = [ row [ <NUM_LIT:0> ] for row in rows ] <EOL> return slugs <EOL> def get_awards ( slug ) : <EOL> url = "<STR_LIT>" . format ( <EOL> slug = slug <EOL> ) <EOL> print "<STR_LIT>" , url <EOL> resp = requests . get ( url ) <EOL> return resp . json ( ) <EOL> def pick_random_bronze_or_better_oa_award ( ) : <EOL> slugs = get_slugs ( ) <EOL> random . shuffle ( slugs ) <EOL> for slug in slugs : <EOL> awards = get_awards ( slug ) <EOL> oa_award = awards [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , slug , "<STR_LIT>" , oa_award [ "<STR_LIT>" ] <EOL> if oa_award [ "<STR_LIT>" ] < <NUM_LIT:4> : <EOL> print "<STR_LIT>" , slug <EOL> break <EOL> return <EOL> def write_to_csv ( slugs ) : <EOL> rows = [ ] <EOL> for slug in slugs : <EOL> awards = get_awards ( slug ) <EOL> vals_list = awards [ <NUM_LIT:0> ] [ "<STR_LIT>" ] . values ( ) <EOL> rows . append ( vals_list ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:wb>' ) as csvfile : <EOL> newCsv = csv . writer ( csvfile , delimiter = '<STR_LIT:U+002C>' , <EOL> quotechar = '<STR_LIT:">' , quoting = csv . QUOTE_MINIMAL ) <EOL> for row in rows : <EOL> newCsv . writerow ( row ) <EOL> pick_random_bronze_or_better_oa_award ( ) </s>
