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

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

Allow user to choose preferred folder for download otc_db_download (4) #79

Closed EOstridge closed 1 year ago

EOstridge 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

adamakram1 commented 1 year ago

Value (4)