Debian Codegraph @

download-pubmed

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # Public domain notice for all NCBI EDirect scripts is located at:
4 # https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice
5
6 useFtp=true
7 useHttps=false
8
9 while [scip-shell system . . `[`. $# -gt 0 ]
10 do
11 case "$1" in
12 -ftp )
13 useFtp=true
14 useHttps=false
15 shift
16 ;;
17 -http | -https )
18 useFtp=false
19 useHttps=true
20 shift
21 ;;
22 * )
23 break
24 ;;
25 esac
26 done
27
28 DownloadOneByFTPscip-shell shell shell-project 0.0.0 DownloadOneByFTP().() {
29
30 dir="$1"
31 fl="$2"
32
33 url="ftp.ncbi.nlm.nih.gov/pubmed/${dir}"
34
35 echoscip-shell system . . echo. "$fl" |
36 nquire -asp "${url}"
37
38 # delete if file is present but empty
39 if [scip-shell system . . `[`. -f "$fl" ] && [scip-shell system . . `[`. ! -s "$fl" ]
40 then
41 rmscip-shell system . . rm. -f "$fl"
42 fi
43
44 # retry if no file
45 if [scip-shell system . . `[`. ! -f "$fl" ]
46 then
47 sleepscip-shell system . . sleep. 10
48 echoscip-shell system . . echo. "First Failed Download Retry" >&2
49 echoscip-shell system . . echo. "$fl" |
50 nquire -asp "${url}"
51 fi
52
53 # retry again if still no file
54 if [scip-shell system . . `[`. ! -f "$fl" ]
55 then
56 sleepscip-shell system . . sleep. 10
57 echoscip-shell system . . echo. "Second Failed Download Retry" >&2
58 echoscip-shell system . . echo. "$fl" |
59 nquire -asp "${url}"
60 fi
61
62 # verify contents
63 if [scip-shell system . . `[`. -s "$fl" ]
64 then
65 errs=$( (gunzipscip-shell system . . gunzip. -c "$fl" | xtract -mixed -verify) 2>&1 )
66 if [scip-shell system . . `[`. -n "$errs" ]
67 then
68 # delete and retry one more time
69 rmscip-shell system . . rm. -f "$fl"
70 sleepscip-shell system . . sleep. 10
71 echoscip-shell system . . echo. "Invalid Contents Retry" >&2
72 echoscip-shell system . . echo. "$fl" |
73 nquire -asp "${url}"
74 if [scip-shell system . . `[`. -s "$fl" ]
75 then
76 errs=$( (gunzipscip-shell system . . gunzip. -c "$fl" | xtract -mixed -verify) 2>&1 )
77 if [scip-shell system . . `[`. -n "$errs" ]
78 then
79 rmscip-shell system . . rm. -f "$fl"
80 frst=$( echoscip-shell system . . echo. "$errs" | headscip-shell system . . head. -n 1 )
81 echoscip-shell system . . echo. "ERROR invalid file '$fl' deleted, errors start with '$frst'" >&2
82 fi
83 else
84 echoscip-shell system . . echo. "Download Attempts Failed" >&2
85 fi
86 fi
87 else
88 rmscip-shell system . . rm. -f "$fl"
89 echoscip-shell system . . echo. "Download of '$fl' Failed" >&2
90 fi
91 }
92
93 DownloadOneByHTTPSscip-shell shell shell-project 0.0.0 DownloadOneByHTTPS().() {
94
95 dir="$1"
96 fl="$2"
97
98 url="https://ftp.ncbi.nlm.nih.gov/pubmed/${dir}"
99
100 nquire -bulk -get "${url}" "$fl" > "$fl"
101
102 # delete if file is present but empty
103 if [scip-shell system . . `[`. -f "$fl" ] && [scip-shell system . . `[`. ! -s "$fl" ]
104 then
105 rmscip-shell system . . rm. -f "$fl"
106 fi
107
108 # retry if no file
109 if [scip-shell system . . `[`. ! -f "$fl" ]
110 then
111 sleepscip-shell system . . sleep. 10
112 echoscip-shell system . . echo. "First Failed Download Retry" >&2
113 nquire -bulk -get "${url}" "$fl" > "$fl"
114 fi
115
116 # retry again if still no file
117 if [scip-shell system . . `[`. ! -f "$fl" ]
118 then
119 sleepscip-shell system . . sleep. 10
120 echoscip-shell system . . echo. "Second Failed Download Retry" >&2
121 nquire -bulk -get "${url}" "$fl" > "$fl"
122 fi
123
124 # verify contents
125 if [scip-shell system . . `[`. -s "$fl" ]
126 then
127 errs=$( (gunzipscip-shell system . . gunzip. -c "$fl" | xtract -mixed -verify) 2>&1 )
128 if [scip-shell system . . `[`. -n "$errs" ]
129 then
130 # delete and retry one more time
131 rmscip-shell system . . rm. -f "$fl"
132 sleepscip-shell system . . sleep. 10
133 echoscip-shell system . . echo. "Invalid Contents Retry" >&2
134 nquire -bulk -get "${url}" "$fl" > "$fl"
135 if [scip-shell system . . `[`. -s "$fl" ]
136 then
137 errs=$( (gunzipscip-shell system . . gunzip. -c "$fl" | xtract -mixed -verify) 2>&1 )
138 if [scip-shell system . . `[`. -n "$errs" ]
139 then
140 rmscip-shell system . . rm. -f "$fl"
141 frst=$( echoscip-shell system . . echo. "$errs" | headscip-shell system . . head. -n 1 )
142 echoscip-shell system . . echo. "ERROR invalid file '$fl' deleted, errors start with '$frst'" >&2
143 fi
144 fi
145 fi
146 else
147 rmscip-shell system . . rm. -f "$fl"
148 echoscip-shell system . . echo. "Download of '$fl' Failed" >&2
149 fi
150 }
151
152 DownloadSectionscip-shell shell shell-project 0.0.0 DownloadSection().() {
153
154 dir="$1"
155
156 if [scip-shell system . . `[`. "$useFtp" = true ]
157 then
158 nquire -lst ftp.ncbi.nlm.nih.gov pubmed "$dir" |
159 grepscip-shell system . . grep. -v ".md5" | grepscip-shell system . . grep. "xml.gz" |
160 skip-if-file-exists |
161 while read fl
162 do
163 sleepscip-shell system . . sleep. 1
164 echoscip-shell system . . echo. "$fl"
165 DownloadOneByFTPscip-shell shell shell-project 0.0.0 DownloadOneByFTP(). "$dir" "$fl"
166 done
167 elif [scip-shell system . . `[`. "$useHttps" = true ]
168 then
169 nquire -get https://ftp.ncbi.nlm.nih.gov pubmed "$dir" |
170 xtract -pattern a -if a -starts-with pubmed -and a -ends-with ".xml.gz" -element a |
171 skip-if-file-exists |
172 while read fl
173 do
174 sleepscip-shell system . . sleep. 1
175 echoscip-shell system . . echo. "$fl"
176 DownloadOneByHTTPSscip-shell shell shell-project 0.0.0 DownloadOneByHTTPS(). "$dir" "$fl"
177 done
178 fi
179 }
180
181 if [scip-shell system . . `[`. "$#" -eq 0 ]
182 then
183 DownloadSectionscip-shell shell shell-project 0.0.0 DownloadSection(). "baseline"
184 if [scip-shell system . . `[`. $? -ne 0 ]
185 then
186 DownloadSectionscip-shell shell shell-project 0.0.0 DownloadSection(). "baseline"
187 fi
188 DownloadSectionscip-shell shell shell-project 0.0.0 DownloadSection(). "updatefiles"
189 if [scip-shell system . . `[`. $? -ne 0 ]
190 then
191 DownloadSectionscip-shell shell shell-project 0.0.0 DownloadSection(). "updatefiles"
192 fi
193 fi
194
195 while [scip-shell system . . `[`. "$#" -gt 0 ]
196 do
197 sect="$1"
198 shift
199 DownloadSectionscip-shell shell shell-project 0.0.0 DownloadSection(). "$sect"
200 if [scip-shell system . . `[`. $? -ne 0 ]
201 then
202 DownloadSectionscip-shell shell shell-project 0.0.0 DownloadSection(). "$sect"
203 fi
204 done