def create_today_folder():
'''
Create a folder, named with the days data, so that timetables can be saved locally
'''
today = str(date.today())
downloads_folder = get_user_downloads_folder()
The above will result in an uncaught exception if downloads doesn't exist. There is a print message earlier in the code (Line 31) which goes some way to helping the user, however it won't appear in the StackTrace.
Suggested Approach
One suggestion for a better approach would be to:
Remove the else block from Line 30
Enclose the rest of the function in a try/catch (catch the specific exception) - first, allow the user to choose a download folder; if still an exception, set the exception error message to the message at Line 31.
Refactoring
# list out the file names in the downloads folder
files = os.listdir(downloads_folder)
# create the path for today folder in downloads
today_folder_path = downloads_folder + '/' + today
# if timetable output folder is not in downloads, create
if today not in files:
os.mkdir(today_folder_path)
else:
print('file with todays date already exists')
return today_folder_path
Please replace the above with one of the following code options for best practice - the user doesn't need a feedback message.
Issue
The above will result in an uncaught exception if downloads doesn't exist. There is a print message earlier in the code (Line 31) which goes some way to helping the user, however it won't appear in the StackTrace.
Suggested Approach
One suggestion for a better approach would be to:
Refactoring
Please replace the above with one of the following code options for best practice - the user doesn't need a feedback message.
Use: https://www.tutorialspoint.com/How-can-I-create-a-directory-if-it-does-not-exist-using-Python
Please combine steps for neater code wherever possible.
The above isn't needed as you would use
path.exists(path)
instead.