From 476123bae4dc4157b0d76d401eff4652ebfd8155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Tue, 1 Dec 2020 13:45:50 +0100 Subject: [PATCH] Temporary fix for Tukui API --- CB/Core.py | 24 ++++++++++++++++++------ CB/Tukui.py | 18 +++++++++--------- CB/__init__.py | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CB/Core.py b/CB/Core.py index c27c1f4..a85b9f5 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -40,6 +40,7 @@ def __init__(self): self.dirIndex = None self.cfCache = {} self.wowiCache = {} + self.tukuiCache = None self.checksumCache = {} self.scraper = cloudscraper.create_scraper() @@ -186,20 +187,23 @@ 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') @@ -207,9 +211,10 @@ def parse_url(self, url): 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') @@ -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')) diff --git a/CB/Tukui.py b/CB/Tukui.py index 0e1231e..3c522fd 100644 --- a/CB/Tukui.py +++ b/CB/Tukui.py @@ -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'] diff --git a/CB/__init__.py b/CB/__init__.py index c85376a..09b4187 100644 --- a/CB/__init__.py +++ b/CB/__init__.py @@ -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 ' __docformat__ = 'restructuredtext en'