department-for-transport-BODS / bods-data-extractor

A python client for downloading and extracting data from the UK Bus Open Data Service
Other
44 stars 8 forks source link

Downloads Folder Specification (3) #90

Open adamakram1 opened 1 year ago

adamakram1 commented 1 year ago

Is your feature request related to a problem? Please describe. It would be useful to be able to choose where to save the download file.

Describe the solution you'd like A change to the get_user_downloads_folder function within the otc_db_download file to allow a choice of folder rather than always choosing the downloads folder, or downloading to the current directory instead of the downloads folder.

def get_user_downloads_folder():
   if platform == "win32":
        downloads_folder = str(Path.home() / "Downloads")

    elif platform == "darwin" or "linux":
        # for macOS or linux
        downloads_folder = str(os.path.join(Path.home(), "Downloads"))

    else:
        print("Unrecognised OS, cannot locate downloads folder")
        downloads_folder = ""

    return downloads_folder

Refactoring

The function is currently doing extra logic. Make the check for exists first, then if not create the folder.

Use standard methods for checking if exists, see https://www.tutorialspoint.com/How-can-I-create-a-directory-if-it-does-not-exist-using-Python