download file from url - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: download file from url (/thread-30601.html) |
download file from url - fernandosianet - Oct-27-2020 Hi folks I know how to download with the direct link, but we always have updates. import requests print ('Download') url = 'https://github.com/roundcube/roundcubemail/releases/download/1.4.9/roundcubemail-1.4.9-complete.tar.gz' r = requests.get (url) filename = url.split ('/') [- 1] with open (filename, 'wb') as output_file: output_file.write (r.content) print ('Download Completed')How can I download the latest version without having to copy the link and edit my script. Could you please help me? Best Regards RE: download file from url - Axel_Erfurt - Oct-27-2020 use url = 'https://github.com/roundcube/roundcubemail/archive/master.zip'
RE: download file from url - fernandosianet - Oct-27-2020 (Oct-27-2020, 06:53 PM)Axel_Erfurt Wrote: use Thank you Axel_Erfurt But, master.zip is just a snapshot from the GIT repository and is **Not A STABLE version of Roundcube**. It's not recommended to replace an existing installation of Roundcube with this version. There must be a way for the script to download the latest version RE: download file from url - bowlofred - Oct-29-2020 Something like: import requests REPO_NAME = "roundcube/roundcubemail" GITHUB_URL = "https://api.github.com/repos/" latest = requests.get(f"{GITHUB_URL}{REPO_NAME}/releases/latest").json() download_url = [x["browser_download_url"] for x in latest["assets"] if x["name"].endswith("complete.tar.gz")][0] print(f"Download URL is {download_url}") |