|
1 | 1 | import requests |
| 2 | +import subprocess |
| 3 | +import tempfile |
| 4 | +from pathlib import Path |
2 | 5 |
|
| 6 | +from tqdm import tqdm |
3 | 7 |
|
4 | | -def download(): |
5 | | - url = 'https://www.facebook.com/favicon.ico' |
6 | | - r = requests.get(url, allow_redirects=True) |
7 | 8 |
|
8 | | - open('facebook.ico', 'wb').write(r.content) |
| 9 | +from codebots.cli.cli import main |
| 10 | + |
| 11 | + |
| 12 | +def download(url='https://github.com/jgm/pandoc/releases/download/2.15/pandoc-2.15-windows-x86_64.msi'): |
| 13 | + |
| 14 | + # r = requests.get(url, allow_redirects=True) |
| 15 | + |
| 16 | + # Streaming, so we can iterate over the response. |
| 17 | + r = requests.get(url, stream=True) |
| 18 | + total_size_in_bytes = int(r.headers.get('content-length', 0)) |
| 19 | + block_size = 1024 # 1 Kibibyte |
| 20 | + progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True) |
| 21 | + with open('C:/temp/pandoc.msi', 'wb') as f: |
| 22 | + for data in r.iter_content(block_size): |
| 23 | + progress_bar.update(len(data)) |
| 24 | + f.write(data) |
| 25 | + progress_bar.close() |
| 26 | + if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes: |
| 27 | + print("ERROR, something went wrong") |
| 28 | + |
| 29 | + # with open('C:/temp/pandoc.msi', 'wb') as f: |
| 30 | + # f.write(r.content) |
| 31 | + # print(r) |
| 32 | + |
| 33 | + # temp_dir = tempfile.TemporaryDirectory() |
| 34 | + # try: |
| 35 | + # process = subprocess.Popen(Path().joinpath(temp_dir.name, 'pandoc.msi'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) |
| 36 | + # except: |
| 37 | + # temp_dir.cleanup() |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + download() |
0 commit comments