def fetch_report(game: Game): for retry_duration in RETRY_DURATIONS: try: return requests.get(game.report_source_url(), stream=True) except requests.exceptions.ConnectionError as ex: LOGGER.warning('Could not fetch report %s', game) if retry_duration == MAX_RETRY_DURATION: raise ex LOGGER.debug('Now wating for %s', retry_duration) time.sleep(retry_duration.total_seconds())
def download_report(game: Game, path: Path): url = game.report_source_url() try: content: bytes = http.get_file(url) except http.EmptyResponseError: LOGGER.warning('SKIPPING Report (empty file): %s - %s', game.report_number, game) return path.write_bytes(content)