Fixed OSError on invalid filename

Added `pathvalidate` as a requirement (https://pypi.org/project/pathvalidate/).
This commit is contained in:
Anders 2023-01-05 23:53:54 +01:00 committed by GitHub
parent fd92a9d998
commit 6c5f908c8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -7,6 +7,7 @@ from timeit import default_timer
from datetime import datetime from datetime import datetime
import argparse import argparse
from dotenv import load_dotenv from dotenv import load_dotenv
from pathvalidate import sanitize_filename
from time import sleep from time import sleep
# when rate-limited, add this to the wait time # when rate-limited, add this to the wait time
@ -402,6 +403,7 @@ def save_files(out_dir):
start = default_timer() start = default_timer()
for file_info in get_file_list(): for file_info in get_file_list():
url = file_info["url_private"] url = file_info["url_private"]
file_info["name"] = sanitize_filename(file_info["name"])
destination_filename = "{id}-{name}".format(**file_info) destination_filename = "{id}-{name}".format(**file_info)
files_dir = os.path.join(out_dir, "files") files_dir = os.path.join(out_dir, "files")
os.makedirs(files_dir, exist_ok=True) os.makedirs(files_dir, exist_ok=True)
@ -465,7 +467,7 @@ if __name__ == "__main__":
if a.o is None and a.files: if a.o is None and a.files:
print("If you specify --files you also need to specify an output directory with -o") print("If you specify --files you also need to specify an output directory with -o")
sys.exit(1) sys.exit(1)
if a.o is not None: if a.o is not None:
out_dir_parent = os.path.abspath( out_dir_parent = os.path.abspath(
os.path.expanduser(os.path.expandvars(a.o)) os.path.expanduser(os.path.expandvars(a.o))

View file

@ -1,3 +1,4 @@
Flask~=1.1.2 Flask~=1.1.2
requests~=2.24.0 requests~=2.24.0
python-dotenv~=0.15.0 python-dotenv~=0.15.0
pathvalidate~=2.5.2