(url, temp_file)
| 164 | |
| 165 | |
| 166 | def http_get(url, temp_file): |
| 167 | req = requests.get(url, stream=True) |
| 168 | content_length = req.headers.get('Content-Length') |
| 169 | total = int(content_length) if content_length is not None else None |
| 170 | progress = tqdm(unit="B", total=total) |
| 171 | for chunk in req.iter_content(chunk_size=1024): |
| 172 | if chunk: # filter out keep-alive new chunks |
| 173 | progress.update(len(chunk)) |
| 174 | temp_file.write(chunk) |
| 175 | progress.close() |
| 176 | |
| 177 | |
| 178 | def get_from_cache(url, cache_dir=None): |