Skip to content

Commit

Permalink
Temporary fix for Tukui API
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Dec 1, 2020
1 parent c7adf09 commit 476123b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
24 changes: 18 additions & 6 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self):
self.dirIndex = None
self.cfCache = {}
self.wowiCache = {}
self.tukuiCache = None
self.checksumCache = {}
self.scraper = cloudscraper.create_scraper()

Expand Down Expand Up @@ -186,30 +187,34 @@ def parse_url(self, url):
elif url.startswith('https://www.tukui.org/addons.php?id='):
if self.clientType == 'wow_classic':
raise RuntimeError('Incorrect client version.')
return TukuiAddon(url, False)
self.bulk_tukui_check()
return TukuiAddon(url, self.tukuiCache)
elif url.startswith('https://www.tukui.org/classic-addons.php?id='):
if self.clientType == 'wow_retail':
raise RuntimeError('Incorrect client version.')
elif url.endswith('1') or url.endswith('2'):
raise RuntimeError('ElvUI and Tukui cannot be installed this way.')
return TukuiAddon(url, True)
self.bulk_tukui_check()
return TukuiAddon(url, self.tukuiCache)
elif url.startswith('https://github.com/'):
return GitHubAddon(url, self.clientType)
elif url.lower() == 'elvui':
if self.clientType == 'wow_retail':
return TukuiAddon('ElvUI', False, 'elvui')
return TukuiAddon('ElvUI', self.tukuiCache, 'elvui')
else:
return TukuiAddon('2', True)
self.bulk_tukui_check()
return TukuiAddon('2', self.tukuiCache)
elif url.lower() == 'elvui:dev':
if self.clientType == 'wow_retail':
return GitLabAddon('ElvUI', '60', 'elvui/elvui', 'development')
else:
return GitLabAddon('ElvUI', '492', 'elvui/elvui-classic', 'development')
elif url.lower() == 'tukui':
if self.clientType == 'wow_retail':
return TukuiAddon('Tukui', False, 'tukui')
return TukuiAddon('Tukui', self.tukuiCache, 'tukui')
else:
return TukuiAddon('1', True)
self.bulk_tukui_check()
return TukuiAddon('1', self.tukuiCache)
elif url.lower() == 'shadow&light:dev':
if self.clientType == 'wow_retail':
return GitLabAddon('ElvUI Shadow & Light', '45', 'shadow-and-light/shadow-and-light', 'dev')
Expand Down Expand Up @@ -556,6 +561,13 @@ def bulk_check(self, addons):
for addon in payload:
self.wowiCache[str(addon['UID'])] = addon

@retry(custom_error='Failed to parse Tukui API data')
def bulk_tukui_check(self):
if not self.tukuiCache:
self.tukuiCache = requests.get(f'https://www.tukui.org/api.php?'
f'{"addons" if self.clientType == "wow_retail" else "classic-addons"}',
headers=HEADERS, timeout=5).json()

def detect_accounts(self):
if os.path.isdir(Path('WTF/Account')):
accounts = os.listdir(Path('WTF/Account'))
Expand Down
18 changes: 9 additions & 9 deletions CB/Tukui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

class TukuiAddon:
@retry()
def __init__(self, url, isclassic, special=None):
def __init__(self, url, checkcache, special=None):
if special:
self.payload = requests.get(f'https://www.tukui.org/client-api.php?ui={special}',
headers=HEADERS, timeout=5)
self.payload = requests.get(f'https://www.tukui.org/api.php?ui={special}',
headers=HEADERS, timeout=5).json()
else:
project = re.findall(r'\d+', url)[0]
self.payload = requests.get(f'https://www.tukui.org/api.php?'
f'{"classic-" if isclassic else ""}addon={project}', headers=HEADERS, timeout=5)
if self.payload.text == '':
raise RuntimeError(url)
else:
self.payload = self.payload.json()
for addon in checkcache:
if addon['id'] == project:
self.payload = addon
break
else:
raise RuntimeError(f'{url}\nProject not found.')
self.name = self.payload['name'].strip().strip('\u200b')
self.downloadUrl = self.payload['url']
self.currentVersion = self.payload['version']
Expand Down
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
from rich.terminal_theme import TerminalTheme

__version__ = '3.15.2'
__version__ = '3.15.3'
__license__ = 'GPLv3'
__copyright__ = '2019-2020, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down

0 comments on commit 476123b

Please sign in to comment.