-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathversioncheck.py
More file actions
48 lines (43 loc) · 1.58 KB
/
versioncheck.py
File metadata and controls
48 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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/latest"
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(
"a",
{
"class": "Link",
"href": "/{}/{}/releases".format(self.owner, self.repo),
},
)
.find_next("a", {"class": "Link"})
.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,
)
except AttributeError:
return (
"Failed to parse release data, consider contacting JoshuaMK: joshuamkw2002@gmail.com",
False,
)