#!/bin/bash

#Goal: Takes a list of BibCodes and generates authors of corresponding papers
#
#usage: ./cites2authors input_bc_file 
#input file .. list of BibCodes 

  if [[ -z $1 ]]; then
    echo "exit: need input BibCode file"
    exit -1
  fi

ADS_Token=$(cat ADS_Token)
Auth="Authorization: Bearer:$ADS_Token"
Query="https://api.adsabs.harvard.edu/v1/search/query?q=bibcode:"
Output="&fl=author"


for infile in $*
  do
    echo "file: " $infile
    outfile=Authors_$infile
    if [ -f $outfile ]; then rm $outfile; fi

    sed '/^#/d' $infile | while read BibCode
      do
        echo $BibCode
        curl -H "$Auth" "$Query$BibCode$Output" | \
		jq  '.response.docs[] | .author[]' | sed 's/"//g' \
		| tee >> $outfile
    done
done
