From bb2a2e758aff1953b0275a0fe18fb14ed1dd3daf Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Tue, 7 Sep 2021 21:53:36 -0300 Subject: [PATCH] Avoid KeyError on Pocket API parser When trying to import my pocket library I got a lot of ` KeyError` on Python. Pocket API has a few idiosyncrasies, such as sometimes returning the keys on json, sometimes not. ` ` ` sh archivebox add --parser pocket_api pocket://my_username ` ` ` Gave me this errors ` ` ` File "/app/archivebox/parsers/pocket_api.py", line 54, in link_from_article title = article['resolved_title'] or article['given_title'] or url KeyError: 'resolved_title' ` ` ` This commit are the patches I've changed to successfully import my library --- archivebox/parsers/pocket_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archivebox/parsers/pocket_api.py b/archivebox/parsers/pocket_api.py index afad70ed..c51d1103 100644 --- a/archivebox/parsers/pocket_api.py +++ b/archivebox/parsers/pocket_api.py @@ -47,11 +47,11 @@ def get_pocket_articles(api: Pocket, since=None, page=0): def link_from_article(article: dict, sources: list): - url: str = article['resolved_url'] or article['given_url'] + url: str = articl.get('resolved_url') or article['given_url'] broken_protocol = _BROKEN_PROTOCOL_RE.match(url) if broken_protocol: url = url.replace(f'{broken_protocol.group(1)}:/', f'{broken_protocol.group(1)}://') - title = article['resolved_title'] or article['given_title'] or url + title = article.get('resolved_title') or article.get('given_title') or url return Link( url=url,