From 66696c57333e33918bf92354ca429fb17d8aa683 Mon Sep 17 00:00:00 2001 From: 17acres Date: Thu, 6 May 2021 13:09:56 -0400 Subject: [PATCH] Replace important invalid characters in filename strings with useful separators --- export.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/export.py b/export.py index 8b742b1..e12b84d 100644 --- a/export.py +++ b/export.py @@ -140,6 +140,9 @@ class courseView(): def makeValidFilename(input_str): # Remove invalid characters valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) + input_str = input_str.replace("+"," ") # Canvas default for spaces + input_str = input_str.replace(":","-") + input_str = input_str.replace("/","-") input_str = "".join(c for c in input_str if c in valid_chars) # Remove leading and trailing whitespace @@ -150,9 +153,12 @@ def makeValidFilename(input_str): def makeValidFolderPath(input_str): # Remove invalid characters valid_chars = "-_.()/ %s%s" % (string.ascii_letters, string.digits) + input_str = input_str.replace("+"," ") # Canvas default for spaces + input_str = input_str.replace(":","-") + input_str = input_str.replace("/","-") input_str = "".join(c for c in input_str if c in valid_chars) - # Remove leading and trailing whitespace + # Remove leading and trailing whitespace, separators input_str = input_str.lstrip().rstrip().strip("/").strip("\\") # Replace path separators with OS default