Created
September 9, 2016 09:08
-
-
Save eszterkv/6357d9f6d7d00c9874ebd6e0316777f3 to your computer and use it in GitHub Desktop.
Downloads the file on the given url and saves it to the current directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import os.path | |
import requests | |
def dl(url): | |
''' | |
Downloads the file on the given url and saves it to the current directory. | |
''' | |
r = requests.get(url) | |
if r.status_code >= 400: | |
print('File not found at URL %s' % url) | |
return | |
filename = url.split('/')[-1] | |
with open(filename, 'wb') as f: | |
f.write(r.content) | |
print('Successfully downloaded %s from %s/' % (filename, ('/').join(url.split('/')[:-1]))) | |
f.close() | |
if __name__ == '__main__': | |
url = input('Enter URL of the file to download: ') | |
dl(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment