#!/usr/bin/env python # dois2metadata.py - given csv file containing a column named 'doi', save metadata describing them # Eric Lease Morgan # (c) University of Notre Dame; distributed under GNU Public License # January 19, 2024 - first cut; in the middle of a creative fit # January 26, 2024 - tweaking for a specific project # configure CACHE = './etc/unpaywall.cache' COLUMN = 'doi' METADATA = './etc/metadata.csv' # require from unpywall import Unpywall from unpywall.cache import UnpywallCache import sys import pandas as pd # get input if len( sys.argv ) != 2 : sys.exit( 'Usage: ' + sys.argv[ 0 ] + " " ) csv = sys.argv[ 1 ] # initialize Unpywall.init_cache( UnpywallCache( CACHE ) ) # read dois, process them, output, and done dois = list( pd.read_csv( csv )[ COLUMN ] ) metadata = Unpywall.doi( dois=dois, progress=True, errors='ignore' ) # output the tiniest bit of statistics sys.stderr.write( str( metadata.oa_status.value_counts(normalize=True) ) + '\n' ) # output the metadata and done with open( METADATA, 'w' ) as handle : handle.write( metadata.to_csv( index=False ) ) exit()