Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created August 8, 2020 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/f71eb7332e9ef373deb6388876321af6 to your computer and use it in GitHub Desktop.
Save Allwin12/f71eb7332e9ef373deb6388876321af6 to your computer and use it in GitHub Desktop.
import requests
import pkg_resources
from bs4 import BeautifulSoup
from pkg_resources import parse_version
from subprocess import call
base_url = "https://pypi.org/project/"
for pkg in pkg_resources.working_set:
original_version = pkg.version
sys_package_name = pkg.project_name
html = requests.get(base_url + pkg.project_name)
soup = BeautifulSoup(html.text, 'html')
pypi_package_name, pypi_version = soup.find('h1', class_='package-header__name').text.strip().split(' ')
print("{}=={} {}=={}".format(sys_package_name, original_version, pypi_package_name, pypi_version))
if parse_version(original_version) < parse_version(pypi_version):
print("update required")
choice = input("Do you want to update (y/n)?")
if choice in ['y', 'Y', 'yes', 'YES']:
print("please update")
call("pip install --upgrade " + ''.join(sys_package_name), shell=True)
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment