@option(
        '-f', '--filename', action='store', default=None,
        help='use the provided name as filename'
    )
    def line_download(self, url, filename=None):
        """
        %download URL [-f FILENAME] - download file from URL

        This line magic will download and save a file. By
        default it will use the same filename as the URL.
        You can give it another name using -f.

        Examples:
            %%download http://some/file/from/internet.txt -f myfile.txt
            %%download http://some/file/from/program.ss

        """
        if filename is None:
            parts = urlparse.urlsplit(url)
            #('http', 'example.com', '/somefile.zip', '', '')
            path = parts[2]
            filename = os.path.basename(path)
            if filename != '':
                basename, extname = os.path.splitext(filename)
                if extname == '':
                    filename += ".html"
                filename = filename.replace("~", "")
                filename = filename.replace("%20", "_")
            else:
                filename = "output.html"
        try:
            download(url, filename)
            self.kernel.Print("Downloaded '%s'." % filename)
        except Exception as e:
            self.kernel.Error(str(e))
dataset/ETHPy150Open Calysto/metakernel/metakernel/magics/download_magic.py/DownloadMagic.line_download/original