1
0
Fork 0
This repository has been archived on 2024-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
GeckoLoader/versioncheck.py
2020-11-06 04:14:27 -06:00

26 lines
No EOL
1 KiB
Python

from urllib import request
from bs4 import BeautifulSoup
class Updater(object):
def __init__(self, owner: str, repository: str):
self.owner = owner
self.repo = repository
self.gitReleases = 'https://github.com/{}/{}/releases'
def request_release_data(self):
""" Returns soup data of the repository releases tab """
with request.urlopen(self.gitReleases.format(self.owner, self.repo)) as response:
html = response.read()
return html
def get_newest_version(self) -> tuple:
""" Returns newest release version """
try:
response = self.request_release_data()
soup = BeautifulSoup(response, 'html.parser')
return soup.find('span', {'class': 'css-truncate-target'}).get_text(strip=True), True
except request.HTTPError as e:
return f'HTTP request failed with error code ({e.code})', False
except request.URLError:
return 'Request failed, ensure you have a working internet connection and try again', False