Skip to content

Commit

Permalink
Fixed CurseForge version check
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Mar 14, 2019
1 parent 110f3f1 commit 97ef608
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
7 changes: 5 additions & 2 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
43 changes: 27 additions & 16 deletions CB/CurseForge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.1.0'
__version__ = '1.1.1'
__license__ = 'GPLv3'
__copyright__ = '2019, Paweł Jastrzębski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
Expand Down

0 comments on commit 97ef608

Please sign in to comment.