(cc_list: list[str],
base_url: str,
verbose: bool,
_unused_concur_req: int)
| 58 | |
| 59 | # tag::FLAGS2_DOWNLOAD_MANY_SEQUENTIAL[] |
| 60 | def download_many(cc_list: list[str], |
| 61 | base_url: str, |
| 62 | verbose: bool, |
| 63 | _unused_concur_req: int) -> Counter[DownloadStatus]: |
| 64 | counter: Counter[DownloadStatus] = Counter() # <1> |
| 65 | cc_iter = sorted(cc_list) # <2> |
| 66 | if not verbose: |
| 67 | cc_iter = tqdm.tqdm(cc_iter) # <3> |
| 68 | for cc in cc_iter: |
| 69 | try: |
| 70 | status = download_one(cc, base_url, verbose) # <4> |
| 71 | except httpx.HTTPStatusError as exc: # <5> |
| 72 | error_msg = 'HTTP error {resp.status_code} - {resp.reason_phrase}' |
| 73 | error_msg = error_msg.format(resp=exc.response) |
| 74 | except httpx.RequestError as exc: # <6> |
| 75 | error_msg = f'{exc} {type(exc)}'.strip() |
| 76 | except KeyboardInterrupt: # <7> |
| 77 | break |
| 78 | else: # <8> |
| 79 | error_msg = '' |
| 80 | |
| 81 | if error_msg: |
| 82 | status = DownloadStatus.ERROR # <9> |
| 83 | counter[status] += 1 # <10> |
| 84 | if verbose and error_msg: # <11> |
| 85 | print(f'{cc} error: {error_msg}') |
| 86 | |
| 87 | return counter # <12> |
| 88 | # end::FLAGS2_DOWNLOAD_MANY_SEQUENTIAL[] |
| 89 | |
| 90 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected