Created
September 3, 2017 16:20
-
-
Save tanb/4559cef8ecb36a0ed916ccaa80208c36 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import click | |
@click.command() | |
@click.option('--outfile', '-o') | |
@click.argument('src') | |
def fetch(outfile, src): | |
import requests | |
import os | |
target_filename = src.split('/')[-1] | |
req = requests.get(src, stream=True) | |
if os.path.isdir(outfile): | |
outfile = os.path.join(outfile, target_filename) | |
with open(outfile, 'wb') as f: | |
for chunk in req.iter_content(chunk_size=1024): | |
if chunk: | |
f.write(chunk) | |
f.flush() | |
#print outfile | |
if __name__ == "__main__": | |
fetch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment