From 3d5cc8f41b21a1d4d11d3483a00be64cff8c0d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Wed, 1 Jul 2020 18:18:37 +0200 Subject: [PATCH] Tweaked WoWI parser --- CB/Core.py | 2 +- CB/WoWInterface.py | 11 ++++++----- CB/__init__.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CB/Core.py b/CB/Core.py index eb44690..36a0e77 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -149,7 +149,7 @@ def parse_url(self, url): 'wow' if url in self.config['IgnoreClientVersion'].keys() else self.clientType, self.check_if_dev(url)) elif url.startswith('https://www.wowinterface.com/downloads/'): - return WoWInterfaceAddon(url, self.wowiCache, self.scraper) + return WoWInterfaceAddon(url, self.wowiCache) elif url.startswith('https://www.tukui.org/addons.php?id='): if self.clientType == 'wow_classic': raise RuntimeError('Incorrect client version.') diff --git a/CB/WoWInterface.py b/CB/WoWInterface.py index 9345b48..c75f496 100644 --- a/CB/WoWInterface.py +++ b/CB/WoWInterface.py @@ -2,18 +2,19 @@ import io import re import zipfile -from . import retry +import requests +from . import retry, HEADERS class WoWInterfaceAddon: @retry() - def __init__(self, url, checkcache, scraper): + def __init__(self, url, checkcache): project = re.findall(r'\d+', url)[0] - self.scraper = scraper if project in checkcache: self.payload = checkcache[project] else: - self.payload = self.scraper.get(f'https://api.mmoui.com/v4/game/WOW/filedetails/{project}.json').json() + self.payload = requests.get(f'https://api.mmoui.com/v4/game/WOW/filedetails/{project}.json', + headers=HEADERS).json() if 'ERROR' in self.payload: raise RuntimeError(url) else: @@ -26,7 +27,7 @@ def __init__(self, url, checkcache, scraper): @retry() def get_addon(self): - self.archive = zipfile.ZipFile(io.BytesIO(self.scraper.get(self.downloadUrl).content)) + self.archive = zipfile.ZipFile(io.BytesIO(requests.get(self.downloadUrl, headers=HEADERS).content)) for file in self.archive.namelist(): if '/' not in os.path.dirname(file): self.directories.append(os.path.dirname(file)) diff --git a/CB/__init__.py b/CB/__init__.py index a264c54..df7eeae 100644 --- a/CB/__init__.py +++ b/CB/__init__.py @@ -2,7 +2,7 @@ import random from rich.terminal_theme import TerminalTheme -__version__ = '3.4.1' +__version__ = '3.4.2' __license__ = 'GPLv3' __copyright__ = '2019-2020, Paweł Jastrzębski ' __docformat__ = 'restructuredtext en'