Created
May 28, 2015 21:22
-
-
Save t-8ch/14fa3b521f5c7fa99450 to your computer and use it in GitHub Desktop.
Poor mans crossplatform curl (intended to be used as `python -m requests`)
This file contains 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
from __future__ import print_function | |
from contextlib import closing | |
from sys import argv, exit, stderr | |
from . import get | |
from .compat import urlparse | |
if len(argv) != 2: | |
exit('Usage: {0} URL'.format(argv[0]), file=stderr) | |
url = argv[1] | |
target = urlparse(url).path.split('/')[-1] | |
with open(target, 'xb') as output: | |
with closing(get(url, stream=True)) as r: | |
for chunk in r.iter_content(): | |
output.write(chunk) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment