From 26024e5c82f8d5a4443be368a524585b7cede9b4 Mon Sep 17 00:00:00 2001 From: Jehan Date: Wed, 21 Sep 2016 02:13:50 +0200 Subject: [PATCH] script: work around a KeyError exception in Python Wikipedia lib. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even the test `if hasattr(page, 'links')` would trigger this exception. So I try the approach "Easier to Ask Forgiveness than Permission". Weird stuff but well… Note: I had this exception when running it on the Maltese data. --- script/BuildLangModel.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/script/BuildLangModel.py b/script/BuildLangModel.py index 4a102d3..d44a5f9 100755 --- a/script/BuildLangModel.py +++ b/script/BuildLangModel.py @@ -257,7 +257,10 @@ def visit_pages(titles, depth, lang, logfd): logfd.write("\n{} (revision {})".format(title, page.revision_id)) process_text(page.content, lang) - next_titles += page.links + try: + next_titles += page.links + except KeyError: + pass if depth >= options.max_depth: return