소스 검색

record errors

main
fluffy 3 달 전
부모
커밋
88a192f5dc
1개의 변경된 파일19개의 추가작업 그리고 5개의 파일을 삭제
  1. +19
    -5
      zenius.py

+ 19
- 5
zenius.py 파일 보기

@@ -13,7 +13,6 @@ import requests.exceptions
from bs4 import BeautifulSoup
from frozendict import frozendict


def parse_args(*args):
parser = argparse.ArgumentParser(description="Mirror simfiles from ZIV")

@@ -39,10 +38,17 @@ def parse_args(*args):

return parser.parse_args(*args)

errors = []

@functools.lru_cache()
def retrieve(url, filename, save_headers=None, extract=None, **kwargs):
print(f'Downloading {url} -> {filename}')
remove = False

def record_error(message):
errors.append((url, filename, message))
print(message)

try:
req = requests.get(url, **kwargs, stream=True)
if req.status_code == 200:
@@ -64,16 +70,19 @@ def retrieve(url, filename, save_headers=None, extract=None, **kwargs):
elif req.status_code == 304:
print("Not modified")
else:
print(f"Error: {req.status_code} {req.text}")
record_error(f"Error: {req.status_code} {req.text}")
except requests.exceptions.BaseHTTPError as e:
print(f'Error downloading: {e.msg}')
record_error(f'Error downloading: {e.msg}')
except zipfile.BadZipFile:
print(f'Not a zip file: {filename}')
record_error(f'Not a zip file: {filename}')
remove = True
except KeyboardInterrupt as e:
print('Download aborting...')
record_error('Download aborting...')
remove = True
raise e
except Exception as e:
record_error(f'Unhandled error: {e}')
remove = True
finally:
if remove:
if os.path.isfile(filename):
@@ -196,3 +205,8 @@ def main():

if __name__ == "__main__":
main()

if errors:
print('Downloading got errors:')
for url, filename, message in errors:
print(f'{url} ({filename}): {message}')

불러오는 중...
취소
저장