Commit 9b066d52 authored by Quentin Aristote's avatar Quentin Aristote
Browse files

handle download failure

parent b6abc6d8
......@@ -125,6 +125,11 @@ def downloadFile(html, path = '.') :
:param html: the HTML code to scrape.
:param name: the path from the current directory to save the file to."""
try :
url = HOSTNAME + html.find('a', attrs = {'class' : 'button raised'})['href']
except :
raise FileNotFoundError('the file does not seem available for download.')
directory, filename = os.path.split(path)
if filename == '' :
filename = None
......@@ -132,10 +137,6 @@ def downloadFile(html, path = '.') :
cwd = os.getcwd()
os.chdir(directory)
try :
url = HOSTNAME + html.find('a', attrs = {'class' : 'button raised'})['href']
except :
raise FileNotFoundError('the file does not seem available for download.')
filename, _ = urllib.request.urlretrieve(url, filename = filename)
os.chdir(cwd)
......@@ -190,8 +191,8 @@ def getRecordings(directory = '.',
print('Success.')
except Exception as e :
print('Failure : {exception}'.format(exception = e))
else :
print('File already downloaded.')
else :
print('File already downloaded.')
return None
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment