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
JoshuaMKW ea8e76dae9 Created preliminary usage of all sections
Updated error system
2020-10-03 15:25:18 -05: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) -> str:
""" 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