Created
August 8, 2020 15:14
-
-
Save Allwin12/f71eb7332e9ef373deb6388876321af6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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