Skip to content

Instantly share code, notes, and snippets.

@t-8ch
Created May 28, 2015 21:22
Show Gist options
  • Save t-8ch/14fa3b521f5c7fa99450 to your computer and use it in GitHub Desktop.
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`)
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