Skip to content

Instantly share code, notes, and snippets.

@tanb
Created September 3, 2017 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tanb/4559cef8ecb36a0ed916ccaa80208c36 to your computer and use it in GitHub Desktop.
Save tanb/4559cef8ecb36a0ed916ccaa80208c36 to your computer and use it in GitHub Desktop.
#!/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