Download the file from the provided URL. Use the filename in the URL as the name of the outputed file.
(logger, url)
| 52 | |
| 53 | |
| 54 | def download_file(logger, url): |
| 55 | """ |
| 56 | Download the file from the provided URL. |
| 57 | Use the filename in the URL as the name of the outputed file. |
| 58 | """ |
| 59 | local_filename = url.split("/")[-1] |
| 60 | logger.debug(local_filename) |
| 61 | # NOTE the stream=True parameter |
| 62 | req = requests.get(url, stream=True) |
| 63 | with open(local_filename, "wb") as out_f: |
| 64 | for chunk in req.iter_content(chunk_size=1024): |
| 65 | if chunk: # filter out keep-alive new chunks |
| 66 | out_f.write(chunk) |
| 67 | out_f.close() |
| 68 | return local_filename |
| 69 | |
| 70 | |
| 71 | def main(logger=None): |