Следует признать, что метод jizhihaoSAMA кажется более простым (использование subprocess.Popen
). Тем не менее, вот еще один метод, использующий win32api
:
import requests, win32api
def get_ver_from_url():
r = requests.get('https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US',
allow_redirects=False)
base_usl = r.headers['Location']
delimiter = base_usl.split('/')[-4]
print(delimiter)
return float(delimiter) # You probably want this as a float or decimal, not a string
def get_installed_version():
firefox_filepath = r"C:\Program Files\Mozilla Firefox\firefox.exe"
version_info = win32api.GetFileVersionInfo(firefox_filepath, "\\")
product_version = version_info["ProductVersionMS"] # There is also ProductVersionLS to get the least significant 32 bits of the version number, but that seems unnecessary
product_version = float(f"{product_version >> 16}.{product_version & 0xFFFF}")
return product_version
latest_version = get_ver_from_url()
installed_version = get_installed_version()
print("Installed version:", installed_version)
print("Latest version:", latest_version)
if latest_version > installed_version:
print("Installed version is out of date!")
Вывод:
74.0
Installed version: 73.0
Latest version: 74.0
Installed version is out of date!