@@ -0,0 +1,2645 @@
+%22%22%22%0ADownload the NSF data directly from nsf.gov using the RESTful API.%0AData is downloaded by year. It arrives in zipped XML files. These%0Afiles are written to disk in the current directory using the year%0Afor naming::%0A%0A    %3Cyear%3E.zip%0A%0A%22%22%22%0Aimport os%0Aimport sys%0Aimport logging%0Aimport argparse%0Aimport requests%0A%0A%0ANSF_AWARDS_URL = 'http://www.nsf.gov/awardsearch/download'%0AREQUIRED_PARAMS = ('DownloadFileName', 'All')%0A%0A%0Adef request_data(year, dirpath='./'):%0A    %22%22%22Request data from NSF. Write to disk on response. Note that%0A    the response will come back as a zipped XML file with all award%0A    data for the requested year.%0A%0A    :param str year: The year to request data for.%0A    :param str dirpath: The directory to write the zip file to.%0A    :raises :class:requests.exceptions.HTTPError: If an HTTP error%0A        occurs as a result of the request.%0A%0A    %22%22%22%0A    params = %7B'DownloadFileName': year, 'All': 'true'%7D%0A    logging.info('requesting award data for year: %7B%7D'.format(year))%0A    r = requests.post(NSF_AWARDS_URL, params)%0A%0A    # will raise HTTP error if one occured%0A    r.raise_for_status()%0A%0A    # write results to zip file in designated directory%0A    fname = '%7B%7D.zip'.format(year)%0A    outfile = os.path.join(os.path.abspath(dirpath), fname)%0A    with open(outfile, 'wb') as f:%0A        f.write(r.content)%0A        logging.info('data for %7B%7D written to %7B%7D'.format(year, outfile))%0A%0Adef request_all(*args):%0A    %22%22%22Request data for all years.%22%22%22%0A    start = '1960'%0A    end = '2014'  # TODO: get based on current date%0A    for year in range(int(start), int(end) + 1):%0A        request_data(str(year), *args)%0A%0A%0Adef setup_parser():%0A    parser = argparse.ArgumentParser(%0A        description='Get raw zipped XML NSF award data from nsf.gov.')%0A%0A    parser.add_argument(%0A        'years', action='store', nargs='*',%0A        help='pass one or more years to restrict requests to those years')%0A    parser.add_argument(%0A        '-o', '--outfile', action='store', default='./',%0A        help='write to a particular file, rather than the curdir')%0A    parser.add_argument(%0A        '-v', '--verbose', action='store_true',%0A        help='print verbose output to console')%0A%0A    return parser%0A%0A%0Adef main():%0A    parser = setup_parser()%0A    args = parser.parse_args()%0A%0A    if args.verbose:%0A        logging.basicConfig(%0A            level=logging.INFO,%0A            format='%5B%25(levelname)s%5Ct%25(asctime)s%5D %25(message)s',%0A            handlers=%5Blogging.StreamHandler()%5D%0A        )%0A    if args.years:%0A        for year in args.years:%0A            request_data(year, args.outfile)%0A    else:%0A        request_all(args.outfile)%0A%0A    return 1%0A%0A%0Aif __name__ == %22__main__%22:%0A    sys.exit(main())%0A

Add data download script.