Skip to content

Commit 4bd932a

Browse files
committed
url with variable
1 parent 1035ac9 commit 4bd932a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

wfdb/_rdsamp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import math
55
import sys
66
import configparser
7-
import configparser
87
import requests
98

109
def checkrecordfiles(recordname, filedirectory):
@@ -117,6 +116,7 @@ def dlrecordfiles(pbrecname, targetdir):
117116
- dledfiles: The list of files downloaded from PhysioBank.
118117
119118
"""
119+
physioneturl = "http://physionet.org/physiobank/database/"
120120
pbdir, baserecname=os.path.split(pbrecname)
121121
print('Downloading missing file(s) into directory: ', targetdir)
122122

@@ -132,7 +132,7 @@ def dlrecordfiles(pbrecname, targetdir):
132132
if not os.path.isfile(os.path.join(targetdir, baserecname+".hea")):
133133
# Not calling dlorexit here. Extra instruction of removing the faulty created directory.
134134
try:
135-
remotefile = "http://physionet.org/physiobank/database/"+pbrecname+".hea"
135+
remotefile = physioneturl+pbrecname+".hea"
136136
targetfile = os.path.join(targetdir, baserecname+".hea")
137137
r = requests.get(remotefile)
138138
with open(targetfile, "w") as text_file:
@@ -141,26 +141,26 @@ def dlrecordfiles(pbrecname, targetdir):
141141
except HTTPError:
142142
if madetargetdir:
143143
os.rmdir(targetdir) # Remove the recently created faulty directory.
144-
sys.exit("Attempted to download invalid target file: http://physionet.org/physiobank/database/"+pbrecname+".hea")
144+
sys.exit("Attempted to download invalid target file: {}".format(remotefile))
145145

146146
fields=readheader(os.path.join(targetdir, baserecname))
147147

148148
# Even if the header file exists, it could have been downloaded prior. Need to check validity of link if ANY file is missing.
149149
if fields["nseg"]==1: # Single segment. Check for all the required dat files
150150
for f in fields["filename"]:
151151
if not os.path.isfile(os.path.join(targetdir, f)): # Missing a dat file
152-
dledfiles=dlorexit("http://physionet.org/physiobank/database/"+pbdir+"/"+f, os.path.join(targetdir, f), dledfiles)
152+
dledfiles=dlorexit(physioneturl+pbdir+"/"+f, os.path.join(targetdir, f), dledfiles)
153153

154154
else: # Multi segment. Check for all segment headers and their dat files
155155
for segment in fields["filename"]:
156156
if segment!='~':
157157
if not os.path.isfile(os.path.join(targetdir, segment+".hea")): # Missing a segment header
158-
dledfiles=dlorexit("http://physionet.org/physiobank/database/"+pbdir+"/"+segment+".hea", os.path.join(targetdir, segment+".hea"), dledfiles)
158+
dledfiles=dlorexit(physioneturl+pbdir+"/"+segment+".hea", os.path.join(targetdir, segment+".hea"), dledfiles)
159159
segfields=readheader(os.path.join(targetdir, segment))
160160
for f in segfields["filename"]:
161161
if f!='~':
162162
if not os.path.isfile(os.path.join(targetdir, f)): # Missing a segment's dat file
163-
dledfiles=dlorexit("http://physionet.org/physiobank/database/"+pbdir+"/"+f, os.path.join(targetdir, f), dledfiles)
163+
dledfiles=dlorexit(physioneturl+pbdir+"/"+f, os.path.join(targetdir, f), dledfiles)
164164

165165
print('Download complete')
166166
return dledfiles # downloaded files

0 commit comments

Comments
 (0)