From 97ef6089e5c1688587323f0408a8c74271fa80c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Thu, 14 Mar 2019 11:37:16 +0100 Subject: [PATCH] Fixed CurseForge version check --- CB/Core.py | 7 +++++-- CB/CurseForge.py | 43 +++++++++++++++++++++++++++---------------- CB/__init__.py | 2 +- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/CB/Core.py b/CB/Core.py index 057b9a5..67e3593 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -36,14 +36,17 @@ def save_config(self): json.dump(self.config, outfile, sort_keys=True, indent=4, separators=(',', ': ')) def update_config(self): - if 'Version' not in self.config.keys(): - # 1.1.0 + if 'Version' not in self.config.keys() or self.config['Version'] != __version__: for addon in self.config['Addons']: + # 1.1.0 if 'Checksums' not in addon.keys(): checksums = {} for directory in addon['Directories']: checksums[directory] = dirhash(os.path.join(self.path, directory)) addon['Checksums'] = checksums + # 1.1.1 + if addon['Version'] is None: + addon['Version'] = "1" self.config['Version'] = __version__ self.save_config() diff --git a/CB/CurseForge.py b/CB/CurseForge.py index 68f7148..fc0c891 100644 --- a/CB/CurseForge.py +++ b/CB/CurseForge.py @@ -15,29 +15,40 @@ def __init__(self, url): url = link['href'] + '/files' break self.redirectUrl = url - self.soup = BeautifulSoup(requests.get(url).content, 'html.parser') + self.url = url + self.soup = BeautifulSoup(requests.get(self.url).content, 'html.parser') self.name = self.soup.title.string.split(' - ')[1].strip() self.downloadUrl = url + '/latest' self.currentVersion = None self.archive = None self.directories = [] + def version_search(self, tag): + version = None + table = self.soup.find('table', attrs={'class': 'listing listing-project-file project-file-listing ' + 'b-table b-table-a'}).find('tbody') + for row in table.find_all('tr', attrs={'class': 'project-file-list-item'}): + if tag in str(row.find('td', attrs={'class': 'project-file-release-type'})): + version = row.find('a', attrs={'class': 'overflow-tip twitch-link'}).contents[0].strip() + break + return version + + @retry def get_current_version(self): - try: - table = self.soup.find('table', attrs={'class': 'listing listing-project-file project-file-listing' - ' b-table b-table-a'}).find('tbody') - for row in table.find_all('tr', attrs={'class': 'project-file-list-item'}): - if 'Release' in str(row.find('td', attrs={'class': 'project-file-release-type'})): - self.currentVersion = row.find('a', attrs={'class': 'overflow-tip twitch-link'}).contents[0].strip() - break - if not self.currentVersion: - for row in table.find_all('tr', attrs={'class': 'project-file-list-item'}): - if 'Beta' in str(row.find('td', attrs={'class': 'project-file-release-type'})): - self.currentVersion = row.find('a', attrs={'class': 'overflow-tip twitch-link'}).contents[0]\ - .strip() - break - except Exception: - raise RuntimeError('Failed to parse addon page. URL is wrong or your source has some issues.') + self.currentVersion = self.version_search('Release') + if self.currentVersion is None: + self.currentVersion = self.version_search('Beta') + if self.currentVersion: + return + for page in range(2, 6): + self.soup = BeautifulSoup(requests.get(f'{self.url}?page={page}').content, 'html.parser') + self.currentVersion = self.version_search('Release') + if self.currentVersion is None: + self.currentVersion = self.version_search('Beta') + if self.currentVersion: + break + if self.currentVersion is None: + raise RuntimeError @retry def get_addon(self): diff --git a/CB/__init__.py b/CB/__init__.py index 9744838..db1946e 100644 --- a/CB/__init__.py +++ b/CB/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.1.0' +__version__ = '1.1.1' __license__ = 'GPLv3' __copyright__ = '2019, Paweł Jastrzębski ' __docformat__ = 'restructuredtext en'