Python Forum

Full Version: download file from url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
use

url = 'https://github.com/roundcube/roundcubemail/archive/master.zip'
(Oct-27-2020, 06:53 PM)Axel_Erfurt Wrote: [ -> ]use

url = 'https://github.com/roundcube/roundcubemail/archive/master.zip'

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
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}")