From 297adc62ec5c99b75979bda6eba8f86f6ed625ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Mon, 4 Jan 2016 12:30:24 +0100 Subject: [PATCH] Raise CountryListError if Page exists but no valid Single-Section exists --- countrylist.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/countrylist.py b/countrylist.py index 590e861..0926693 100644 --- a/countrylist.py +++ b/countrylist.py @@ -157,11 +157,18 @@ class CountryList(): # For belgian list we need to select subsection of country belgian = self.detect_belgian() - if belgian: - singles_section = self.wikicode.get_sections( - matches=belgian )[0].get_sections( matches="Singles" )[0] - else: - singles_section = self.wikicode.get_sections(matches="Singles")[0] + # Select Singles-Section + # Catch Error if we have none + try: + if belgian: + singles_section = self.wikicode.get_sections( + matches=belgian )[0].get_sections( matches="Singles" )[0] + else: + singles_section = self.wikicode.get_sections( + matches="Singles" )[0] + + except IndexError: + raise CountryListError( "No Singles-Section found!") # Since we have multiple categories in some countrys we need # to select the first wrapping template