14 """Download and unzip the target file to the destination."""
16 from __future__
import print_function
27 if len(sys.argv) != 3:
28 print(
"Usage: python download_and_unzip.py [zipfile-url] [destination]")
30 download_url = sys.argv[1]
31 destination = sys.argv[2]
33 with tempfile.TemporaryFile()
as tmp_file:
34 r = requests.get(download_url)
35 if r.status_code != requests.codes.ok:
36 print(
"Download %s failed with [%d] \"%s\"" %
37 (download_url, r.status_code, r.text()))
40 tmp_file.write(r.content)
41 print(
"Successfully downloaded from %s", download_url)
42 with zipfile.ZipFile(tmp_file,
'r')
as target_zip_file:
43 target_zip_file.extractall(destination)
44 print(
"Successfully unzip to %s" % destination)
47 if __name__ ==
"__main__":