From a76996df131f670e3d3ba66f19eec221215bd894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Tue, 5 Jul 2022 12:04:05 +0200 Subject: [PATCH] Updated Wago Addons support --- CB/Core.py | 43 ++++++++++++++++++------------------------- CB/WagoAddons.py | 4 +++- CurseBreaker.py | 8 ++++---- Pipfile.lock | 34 +++++++++++++++++----------------- README.md | 2 +- 5 files changed, 43 insertions(+), 48 deletions(-) diff --git a/CB/Core.py b/CB/Core.py index de929a9..89e58b5 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -505,12 +505,8 @@ def search(self, query): payload = requests.get(f'https://addons.wago.io/api/external/addons/_search?query={quote_plus(query.strip())}' f'&game_version={self.clientType}', headers=HEADERS, auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5) - if payload.status_code == 401: - raise RuntimeError('Wago Addons API key is missing or incorrect.') - elif payload.status_code == 403: - raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.') - else: - payload = payload.json() + self.parse_wagoaddons_error(payload.status_code) + payload = payload.json() for result in payload['data']: results.append(result['website_url']) return results @@ -537,18 +533,13 @@ def create_reg(self): '[HKEY_CURRENT_USER\Software\Classes\weakauras-companion\shell\open\command]\n' '@="\\"' + os.path.abspath(sys.executable).replace('\\', '\\\\') + '\\" \\"%1\\""') - @retry(custom_error='Failed to parse the URI.') def parse_wagoapp_payload(self, url): projectid = url.replace('wago-app://addons/', '') payload = requests.get(f'https://addons.wago.io/api/external/addons/{projectid}?game_version=' f'{self.clientType}', headers=HEADERS, auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5) - if payload.status_code == 401: - raise RuntimeError('Wago Addons API key is missing or incorrect.') - elif payload.status_code == 403: - raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.') - else: - payload = payload.json() + self.parse_wagoaddons_error(payload.status_code) + payload = payload.json() return f'https://addons.wago.io/addons/{payload["slug"]}' @retry() @@ -572,12 +563,8 @@ def bulk_check(self, addons): # payload = requests.post(f'https://addons.wago.io/api/external/addons/_recents?game_version=' # f'{self.clientType}', json={'addons': ids_wago}, headers=HEADERS, # auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5) - # if payload.status_code == 401: - # raise RuntimeError('Wago Addons API key is missing or incorrect.') - # elif payload.status_code == 403: - # raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.') - # else: - # payload = payload.json() + # self.parse_wagoaddons_error(payload.status_code) + # payload = payload.json() # for addon in payload['addons']: # self.wagoCache[addon] = payload['addons'][addon] @@ -626,12 +613,8 @@ def detect_addons(self): payload = requests.post(f'https://addons.wago.io/api/external/addons/_match?game_version=' f'{self.clientType}', json={'addons': output}, headers=HEADERS, auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5) - if payload.status_code == 401: - raise RuntimeError('Wago Addons API key is missing or incorrect.') - elif payload.status_code == 403: - raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.') - else: - payload = payload.json() + self.parse_wagoaddons_error(payload.status_code) + payload = payload.json() for addon in payload['addons']: if self.check_if_installed(addon['website_url']): namesinstalled.append(addon['name']) @@ -671,6 +654,16 @@ def export_addons(self): addons.append(url) return f'install {",".join(sorted(addons))}' + def parse_wagoaddons_error(self, code): + if code == 401: + raise RuntimeError('Wago Addons API key is missing or incorrect.') + elif code == 403: + raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.') + elif code == 423: + raise RuntimeError('Provided Wago Addons API key is blocked. Please acquire a new one.') + elif code == 429 or code == 500: + raise RuntimeError('Temporary Wago Addons API issue. Please try later.') + class WagoAddonsHasher: def __init__(self, directory): diff --git a/CB/WagoAddons.py b/CB/WagoAddons.py index 66de698..f73b41a 100644 --- a/CB/WagoAddons.py +++ b/CB/WagoAddons.py @@ -31,7 +31,9 @@ def __init__(self, url, checkcache, clienttype, allowdev, apikey): raise RuntimeError(f'{url}\nWago Addons API key is missing or incorrect.') elif self.payload.status_code == 403: raise RuntimeError(f'{url}\nProvided Wago Addons API key is expired. Please acquire a new one.') - elif self.payload.status_code == 404 or self.payload.status_code == 500: + elif self.payload.status_code == 423: + raise RuntimeError(f'{url}\nProvided Wago Addons API key is blocked. Please acquire a new one.') + elif self.payload.status_code == 404 or self.payload.status_code == 429 or self.payload.status_code == 500: raise RuntimeError(f'{url}\nThis might be a temporary issue with Wago Addons API or the project was ' f'removed/renamed. In this case, uninstall it (and reinstall if it still exists) ' f'to fix this issue.') diff --git a/CurseBreaker.py b/CurseBreaker.py index 87e9c8c..422220f 100644 --- a/CurseBreaker.py +++ b/CurseBreaker.py @@ -180,7 +180,7 @@ def start(self): 'tion.\n') if len(self.core.config['Addons']) == 0: self.console.print('To enable Wago Addons support API key needs to be provided.\nIt can be obtained here: [' - 'link=https://www.patreon.com/wagoio]https://www.patreon.com/wagoio[/link]\nAfter that i' + 'link=https://addons.wago.io/patreon]https://addons.wago.io/patreon[/link]\nAfter that i' 't needs to added to application configuration by using [green]set wago_addons_api[/gree' 'n] command.\nCommand [green]import[/green] might be used to detect already installed ad' 'dons.') @@ -768,7 +768,7 @@ def c_set(self, args): else: self.console.print('[green]Usage:[/green]\n\t[green]set wago_addons_api [API key][/green]\n\t\tSets Wago Ad' 'dons API key required to use Wago Addons as addon source.\n\t\tIt can be obtained here:' - ' [link=https://www.patreon.com/wagoio]https://www.patreon.com/wagoio[/link]\n\t[green]s' + ' [link=https://addons.wago.io/patreon]https://addons.wago.io/patreon[/link]\n\t[green]s' 'et wago_api [API key][/green]\n\t\tSets Wago API key required to access private entries' '.\n\t\tIt can be obtained here: [link=https://wago.io/account]https://wago.io/account[/' 'link]\n\t[green]set wago_wow_account [Account name][/green]\n\t\tSets WoW account used ' @@ -916,8 +916,8 @@ def c_help(self, _): '[green]toggle wago [Username][/green]\n\tEnables/disables automatic Wago updates.\n\tIf a u' 'sername is provided check will start to ignore the specified author.\n' '[green]set wago_addons_api [API key][/green]\n\tSets Wago Addons API key required to use Wa' - 'go Addons as addon source.\n\tIt can be obtained here: [link=https://www.patreon.com/wagoio' - ']https://www.patreon.com/wagoio[/link]\n' + 'go Addons as addon source.\n\tIt can be obtained here: [link=https://addons.wago.io/patreon' + ']https://addons.wago.io/patreon[/link]\n' '[green]set wago_api [API key][/green]\n\tSets Wago API key required to access private entri' 'es.\n\tIt can be obtained here: [link=https://wago.io/account]https://wago.io/account[/link' ']\n' diff --git a/Pipfile.lock b/Pipfile.lock index 761a807..2d15566 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "a19718b57450a54763191521929ad9d8ea372239f973ad4ab941ca622b769cd8" + "sha256": "90dd4d11e8990337dfcd45f4319b17e3773ca1a3e67b9ee8d50cba8223a8497a" }, "pipfile-spec": 6, "requires": { @@ -26,19 +26,19 @@ }, "certifi": { "hashes": [ - "sha256:9c5705e395cd70084351dd8ad5c41e65655e08ce46f2ec9cf6c2c08390f71eb7", - "sha256:f1d53542ee8cbedbe2118b5686372fb33c297fcd6379b050cca0ef13a597382a" + "sha256:84c85a9078b11105f04f3036a9482ae10e4621616db313fe045dd24743a0820d", + "sha256:fe86415d55e84719d75f8b69414f6438ac3547d2078ab91b67e779ef69378412" ], - "markers": "python_version >= '3.6'", - "version": "==2022.5.18.1" + "markers": "python_full_version >= '3.6.0'", + "version": "==2022.6.15" }, "charset-normalizer": { "hashes": [ - "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597", - "sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df" + "sha256:5189b6f22b01957427f35b6a08d9a0bc45b46d3788ef5a92e978433c7a35f8a5", + "sha256:575e708016ff3a5e3681541cb9d79312c416835686d054a23accb873b254f413" ], - "markers": "python_full_version >= '3.5.0'", - "version": "==2.0.12" + "markers": "python_full_version >= '3.6.0'", + "version": "==2.1.0" }, "checksumdir": { "hashes": [ @@ -60,7 +60,7 @@ "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff", "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d" ], - "markers": "python_full_version >= '3.5.0'", + "markers": "python_version >= '3.5'", "version": "==3.3" }, "lupa": { @@ -153,18 +153,18 @@ }, "prompt-toolkit": { "hashes": [ - "sha256:62291dad495e665fca0bda814e342c69952086afb0f4094d0893d357e5c78752", - "sha256:bd640f60e8cecd74f0dc249713d433ace2ddc62b65ee07f96d358e0b152b6ea7" + "sha256:859b283c50bde45f5f97829f77a4674d1c1fcd88539364f1b28a37805cfd89c0", + "sha256:d8916d3f62a7b67ab353a952ce4ced6a1d2587dfe9ef8ebc30dd7c386751f289" ], "index": "pypi", - "version": "==3.0.29" + "version": "==3.0.30" }, "pygments": { "hashes": [ "sha256:5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb", "sha256:dc9c10fb40944260f6ed4c688ece0cd2048414940f1cea51b8b226318411c519" ], - "markers": "python_version >= '3.6'", + "markers": "python_full_version >= '3.6.0'", "version": "==2.12.0" }, "pyparsing": { @@ -192,11 +192,11 @@ }, "requests": { "hashes": [ - "sha256:bc7861137fbce630f17b03d3ad02ad0bf978c844f3536d0edda6499dafce2b6f", - "sha256:d568723a7ebd25875d8d1eaf5dfa068cd2fc8194b2e483d7b1f7c81918dbec6b" + "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983", + "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349" ], "index": "pypi", - "version": "==2.28.0" + "version": "==2.28.1" }, "rich": { "hashes": [ diff --git a/README.md b/README.md index 528b86a..27ecabf 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ By default **CurseBreaker** will create backups of the entire `WTF` directory. ## WAGO ADDONS SUPPORT To use Wago Addons as addon source user needs to provide a personal API key.\ -The key can be obtained [here](https://www.patreon.com/wagoio) and needs to be added to the application configuration by using `set wago_addons_api` command. +The key can be obtained [here](https://addons.wago.io/patreon) and needs to be added to the application configuration by using `set wago_addons_api` command. ## WEAKAURAS SUPPORT **CurseBreaker** by default will try to update all detected WeakAuras and Plater profiles/scripts. Process work the same as WeakAuras Companion.\