#!/bin/bash


#./bc2authors list_of_bibcodes

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

 start=$2
 start=${start:=0}
 echo "startin index: " $start

 ADS_Token=$(cat ADS_Token)
 BQ="Content-Type: big-query/csv"
 Auth="Authorization: Bearer "$ADS_Token
 Query="https://api.adsabs.harvard.edu/v1/search/bigquery?q=*:*"
 Output="&fl=bibcode,title,author_count,author&rows=2000&start=$start"
 XPost=" -X POST -d \\"
 string="curl -H \"$BQ\" -H \"$Auth\" \"$Query$Output\" $XPost"
 echo $string > cmd

echo -n "$'bibcode" >> cmd
awk '{printf "\\n%s", $1}' $bc_file >> cmd
echo -n "'" >> cmd


source cmd | tee OUTPUT
