#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) echo version = 1.46 of yvp 2023 Sep 13 # 2023 Sep 13, 1.46 curl objecting to [pdat] bracket? # 2022 Mar 30, 1.45 the '\' are getting through to pubmed and wrecking the search! # 2021 Nov 28, 1.44: replace wget with curl since curl is installed on macOS # may now be badly broken, curl does not like '[]'. # 2016 Aug 05, 1.43: pubmed changed the way the pmid is reported - broke # 2016 Jul 29, 1.42: switch to https: # https://www.ncbi.nlm.nih.gov/home/develop/https-guidance.shtml # 2015 Nov 06, 1.41: year +1 ok # 2015 Oct 22, 1.40: wget -4 # 2015 Feb 09, 1.39: wget call is duplicated! 'wget wget' => 'wget'! # 2014 Dec 09, 1.38: remove dependency on grabprogram # 2014 Dec 09, 1.37: make more command line less browser dependent # 2014 Dec 06, 1.36: why does yvp hang? yvp 2014 543 45 # 2014 Jan 22, 1.35: `yvp d1994 234 221`: if: Expression Syntax # 2013 Nov 08, 1.34: backup # 2013 Nov 08, 1.33: 'n: Undefined variable.' for `yvp 1985 318 28` # 2013 Oct 17, 1.32: handle medquery # 2013 Oct 15, 1.31: 'PMID:' no longer followed by a space! # 2013 Mar 28, 1.30: 4 arguments: was missing yvp! # 2013 Mar 21, 1.29: 2 arguments: vol, page # 2012 Dec 13, 1.28: clean up # 2012 Dec 13, 1.27: simplify and rebuild - functional with new url call # 2012 Dec 13, 1.26: '%5B' for '[' and '%5D' for ']' now fail at PubMed! # 2012 Jul 15, 1.25: improve synopsis # 2012 Mar 05, 1.24: supposed cosmetic change: yvp order in pubmed search terms # (must consolidate first) # 2011 Sep 04, 1.23: update documentation # 2011 Jun 12, 1.22: buffer say; no more delay # 2010 Dec 08, 1.21: show arguments if bad # 2010 Nov 25, 1.20: delay before closing to allow browser to catch up? # no - just build mechanisms for finding other scripts # 2010 Sep 09, 1.19: more open all pubmed ids!! - browse was not available # 2010 Sep 09, 1.18: open all pubmed ids!! # 2010 Feb 05, 1.17: clean up # 2010 Feb 04, 1.16: clean up # 2010 Feb 04, 1.15: allow multiple keys # 2009 Nov 16, 1.14: use 'PMID: ' as the id line # 2009 Nov 05, 1.13: fix documentation # 2009 Nov 04, 1.12: use browse script # 2009 Oct 21, 1.11: notes on eutils # 2009 Apr 22, 1.10: empty medquery call # 2009 Apr 21, 1.09: handle multiple PMIDs # 2009 Apr 17, 1.08: grab the reference if it was found! # 2008 Aug 18, 1.07: allow pages like: `yvp 2008 3 e2774` # 2008 Aug 05, 1.06: year, volume and page checks # 2007 Nov 01, 1.05: released to the web # 2007 Sep 01, 1.04: handle 1 argument case! # 2007 Jun 30, 1.03: constructed url is now given at end # 2007 Jun 19, 1.02: correct documentation # 2007 Jun 18, 1.01: allow additional tags # 2007 Jun 13, 1.00: origin from avp # Variables to record delays in curl set timing = 1 # default is to report time set timereport = ~/yvp-time.txt set alloweddelay = 2 # seconds allowed for initial curl if ($#argv < 2) then echo 'usage: yvp [year] [volume] [page]' echo 'usage: yvp [year] [volume] [page] [more keys]' echo 'usage: yvp [volume] [page]' echo 'Find article with given year/volume/page in PubMed.' echo "If you have a 'browse script that calls a browser," # usage echo "the browser will be made to point to the page." # usage echo "Also, extract the reference in bibtex format." # usage echo echo "If only two arguments are given, the current year is assumed" echo "These files are put in your home directory:" echo " bib bibformat bibkey" echo "by medquery." echo echo "example call:" echo "yvp 1986 188 415" echo echo "Documentation:" echo "https://alum.mit.edu/www/toms/yvp.html" echo echo "Dependencies:" echo "* browse script - to display a url using a browser" echo -n " The browse script is" if (`which browse | grep '/'| wc -l` > 0) then echo " available. It will be used to pop up your browser." set isbrowser = 1 else echo " NOT available. No browser will be called." set isbrowser = 0 endif # echo "* grabprogram script - to grab a web page with wget to a new name" # echo -n "The grabprogram script is" # if (`which grabprogram | grep '/'| wc -l` > 0) then # echo -n "" # else # echo -n " NOT" # endif # echo " available." # echo "* buffersay" # echo "* wget, see:" # echo " https://alum.mit.edu/www/toms/wget.html" echo "* medlinebib program from" echo " https://alum.mit.edu/www/toms/delila/medlinebib.html" echo " See documentation there." echo "* medlinebibp controls medlinebib:" echo " https://alum.mit.edu/www/toms/ftp/medlinebibp" echo "* medquery script from" echo " https://alum.mit.edu/www/toms/ftp/medquery" echo echo "Dr. Thomas D. Schneider" echo "National Institutes of Health" echo "schneidt@mail.nih.gov" echo "toms@alum.mit.edu (permanent)" echo "https://alum.mit.edu/www/toms (permanent)" # Note: yvp could possibly be written using Eutils: # https://www.ncbi.nlm.nih.gov/books/NBK25501/ # This might make it more stable. # echo 'usage: yvp [volume] [page]' NOT USED!! exit endif # Look for curl program if (`which curl| grep '/'|wc -l` > 0) then echo 'found the curl program' # zzzqqq set grabprogram = "curl -O" # buffersay 'found the grabprogram program' & else # Ok, it's being called as a 'button' on the desktop set me = `whoami` set foundgrabprogram = 0 if (-d ~/script) then if (-f ~/script/grabprogram) then set grabprogram = `ls ~/script/grabprogram` set foundgrabprogram = 1 else set foundgrabprogram = 0 endif else set foundgrabprogram = 0 endif if !($foundgrabprogram) then echo 'Could not find the grabprogram program\!' #buffersay 'Could not find the grabprogram program\!' & echo 'grabprogram should be in your script directory at' #buffersay 'grabprogram should be in your script directory at' & echo "~/script/grabprogram" #buffersay "~/script/yvp" & exit endif endif # Look for browse program if (`which browse| grep '/'|wc -l`> 0) then echo 'found the browse program' set browse = browse set foundbrowse = 1 # buffersay 'found the browse program' & else # Ok, maybe it's being called as a 'button' on the desktop set me = `whoami` set foundbrowse = 0 if (-d ~/script) then if (-f ~/script/browse) then set browse = `ls ~/script/browse` set foundbrowse = 1 else set foundbrowse = 0 endif else set foundbrowse = 0 endif if !($foundbrowse) then echo 'Could not find a browse program\!' # buffersay 'Could not find the browse program\!' & echo 'browse can be in your script directory at' # buffersay 'browse should be in your script directory at' & echo "~/script/browse" # buffersay "~/script/yvp" & # exit endif endif # preset values set year = "" set volume = "" set page = "" set keypart = "" if ($#argv < 4) then if ($#argv == 2) then set year = `date +%Y` set volume = "$1" set page = "$2" echo -n "Using the current year, ${year}," echo " and the given volume ($volume) and page ($page)" else set year = "$1" set volume = "$2" set page = "$3" echo -n "Using the given year ($year)" echo " and the volume ($volume) and page ($page)" endif else # if ($#argv >= 4) then # set the key to be argument 4 and following. set key = "`echo $argv[4-$#argv] | sed 's/ / AND /g'`" set keypart = "+AND+${key}\[All+Fields\]" echo "the set of keys is |$key|" set year = "$1" set volume = "$2" set page = "$3" endif # check that the inputs are integers foreach token ( $year $volume ) if (`echo -n "$token" | tr -d '[:digit:]'| wc -c` > 0) then echo "non digit found in string $token" exit endif end # check values set beep = '' @ yearminusone = $year - 1 if ("$year" != '') then if (("$yearminusone" > `date "+%Y"`)||("$year" < 1500)) then echo "$beep year $year is bad" echo "arguments: $argv" # buffersay "$beep year $year is bad" & exit endif endif if ("$volume" != '') then if ("$volume" < 1) then echo "$beep volume $volume is bad" echo "arguments: $argv" # buffersay "$beep volume $volume is bad" & exit endif endif # allow pages like e2774 in `yvp 2008 3 e2774` # if ("$page" != '') then # if ("$page" < 1) then # echo "$beep page $page is bad" # exit # endif # endif # 2016 jul 29 switch to https: # https://www.ncbi.nlm.nih.gov/home/develop/https-guidance.shtml # set url = "https://www.ncbi.nlm.nih.gov/pubmed?term=${year}[pdat]+AND+${volume}[volume]+AND+${page}[page]${keypart}" #zzzqqq # set url = "https://www.ncbi.nlm.nih.gov/pubmed?term=${year}\[pdat\]+AND+${volume}\[volume\]+AND+${page}\[page\]${keypart}" # 2022 Mar 30 the '\' are getting through to pubmed and wrecking the search! set url = "https://www.ncbi.nlm.nih.gov/pubmed?term=${year}\[pdat\]+AND+${volume}\[volume\]+AND+${page}\[page\]${keypart}" set cleanurl = `echo "$url"|tr -d '\\'` echo "$url" if ($foundbrowse) then $browse "$cleanurl" endif if (`which medquery | grep '/'| wc -l` == 0) then echo 'no medquery program found' exit endif # 2009 Apr 17: if one can get a PMID, call medquery with it! set tmp1 = /tmp/`whoami`1.yvp set tmp2 = /tmp/`whoami`2.yvp #echo "======> $grabprogram $url $tmp1" #$grabprogram "$url" $tmp1 #echo "======> DONE grabprogram" echo '=== yvp BEGIN: ===' if ($timing) then set begtime = `tomdate` endif # wget -4 --no-check-certificate -O "$tmp1" "$url" set Q = '' curl -L -o "$tmp1" "$Q$url$Q" # -L, --location # (HTTP) If the server reports that the requested page has moved # to a different location (indicated with a Location: header and a # 3XX response code), this option will make curl redo the request # on the new place. # sleep 3 # use this to test the timing trigger if ($timing) then set endtime = `tomdate` set t = `diffdate $begtime $endtime | clmn 1` if ("$t" > "$alloweddelay") then echo "" >> $timereport echo "$url" >> $timereport echo -n "$begtime $endtime " >> $timereport diffdate $begtime $endtime >> $timereport set reportingtime = 1 echo "REPORTING DELAY TO $timereport" endif endif echo '=== yvp DONE =====' # grep 'PMID' $tmp1|tr '<>[]' '\n\n\n\n'|grep PMID > $tmp2 # 2009 Nov 16: use 'PMID: ' to identify the PMID line # grep 'PMID: ' $tmp1|tr '<>[]' '\n\n\n\n'|grep PMID > $tmp2 # 2013 Oct 15 the PMID: is now not followed by a space! # grep 'PMID:' $tmp1|tr '<>[]' '\n\n\n\n'|grep PMID > $tmp2 # # 2013 Oct 17: pmid format changed to html apparently # The PMID format is now: #