#!/bin/csh
# file: ads-renew-all
# init: Oct  5 2019  Rob Rutten  Deil
# last: Nov 23 2020  Rob Rutten  Deil
# note: usage = ads-renew-all
#       no longer with parameter days before (never used that since revamp)
#       does NOT call ads-name-renew but ads-name-get in order to
#       make publists as final check only after all collecting

# get current remaining to ADS limit and warn 
curl -v -H "Authorization: Bearer hahahahahahaha" 'https://api.adsabs.harvard.edu/v1/search/query?q=star'
echo ===== "break off if x-ratelimit-remaining < 3000    run takes 2 hours" 
sleep 10

# all <name> distills to /tmp (for accidents) to remove invalid formers
mkdir /tmp/adsbackup
cd ~/rr/www/bibfiles/ads/abs
mv *.txt /tmp/adsbackup
back
cd ~/rr/www/bibfiles/ads/bib
mv *.bib /tmp/adsbackup
back
cd ~/rr/www/bibfiles/ads/abstracts
mv *.html /tmp/adsbackup
back
cd ~/rr/www/bibfiles/ads/publists
mv *.pdf /tmp/adsbackup
back

# renew abs, bib, solabs files for each name in namestrings
cd ~/rr/www/bibfiles/ads/namestrings
foreach file (*)
  ads-name-get $file
end
back

# now zip 
echo " ===== zip the abs and bib collections"
cd ~/rr/www/bibfiles/ads
zip -r abs.zip abs
zip -r bib.zip bib
back

# concatenate all bib files 
find ~/rr/www/bibfiles/ads/bib -name '*.bib' -exec cat {} > ~/rr/www/bibfiles/bigbib/adsfiles.bib \; 

# cleanrenew bibfiles in UU for weblinks before publists (may hang)
cd  ~/rr/www/bibfiles
echo " ===== renew content of dir bibfiles at UU"
sshcleanrrdiruu
back

# finally run make_all_ads_publists as checks; it may hang at some => analyze
cdprintbib
make_all_ads_publists
back

# cleanrenew bibfiles in UU for weblinks after publists (weblinked dir)
cd  ~/rr/www/bibfiles
echo " ===== renew content of dir bibfiles at UU"
sshcleanrrdiruu
back

# manual for check
echo " ##### for publists errors check cdprintbib logbibtexpublist.txt"
echo "       especially for Illegal end"
echo "       or run make_all_ads_publists again in cdprintbib"
echo "       at errors cdprintbib, cat pubname, check bib and namestrings"
echo "       see manual at top emadsjot"

# done
echo ""
echo " ===== ads-renew-all done" 
date 
echo " ===== at the above time"
