From 81e541ef1dfec71a195ca02a7b1cf9bebf18e1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Sat, 26 Dec 2015 12:42:14 +0100 Subject: [PATCH 1/5] Provisonal on wiki activation --- chartsbot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/chartsbot.py b/chartsbot.py index ea5e3af..fb3bc4f 100644 --- a/chartsbot.py +++ b/chartsbot.py @@ -94,6 +94,14 @@ class ChartsBot( ): # Set locale to 'de_DE.UTF-8' locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') + # provisional-onwiki-activation + page_active = pywikibot.Page( self.site, "Benutzer:JogoBot/active" ) + text_active = page_active.get() + + if "true" not in text_active.lower(): + pywikibot.output( "Bot ist deaktiviert!" ) + return False + def run(self): """Process each page from the generator.""" for page in self.generator: @@ -215,7 +223,8 @@ def main(*args): # pages from the wiki simultaneously. gen = pagegenerators.PreloadingGenerator(gen) bot = ChartsBot(gen, always, force_reload) - bot.run() + if bot: + bot.run() else: pywikibot.showHelp() From b6c7a74519c946e4303bdf3347a7de410f2fc9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Mon, 4 Jan 2016 12:28:40 +0100 Subject: [PATCH 2/5] Raise Exception instead of returning False in CountryList.__init__() since returning False is no valid python construct --- countrylist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/countrylist.py b/countrylist.py index 6b76b07..590e861 100644 --- a/countrylist.py +++ b/countrylist.py @@ -66,7 +66,8 @@ class CountryList(): # Check if page exits if not self.page.exists(): - return False + raise CountryListError( "CountryList " + + str(wikilink.title) + " does not exists!" ) # Initialise attributes __attr = ( "wikicode", "entry", "chartein", "_chartein_raw", 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 3/5] 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 From 7bb77e86f6eab13e256284cb996d3ce549e260f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Mon, 4 Jan 2016 12:34:13 +0100 Subject: [PATCH 4/5] Since last_title also referenced the same object we need to re-replace the year for last year's list --- summarypage.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/summarypage.py b/summarypage.py index d859062..923a215 100644 --- a/summarypage.py +++ b/summarypage.py @@ -143,11 +143,8 @@ class SummaryPageEntry(): # Get current year current_year = datetime.now().year - # Store old link.title - link_title = self.countrylist_wikilink.title - # If list is from last year, replace year - if (current_year - 1) in link_title: + if (current_year - 1) in self.countrylist_wikilink.title: self.countrylist_wikilink.title.replace( (current_year - 1), current_year ) @@ -160,7 +157,11 @@ class SummaryPageEntry(): # Maybe fallback to last years list except CountryListError: - self.countrylist_wikilink.title = link_title + # If list is from last year, replace year + if (current_year ) in self.countrylist_wikilink.title: + self.countrylist_wikilink.title.replace( current_year, + (current_year - 1) ) + self.countrylist = CountryList( self.countrylist_wikilink ) self.maybe_parse_countrylist() From 9a24a988f4bb8214a3f2fdc287403813f0134bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Mon, 4 Jan 2016 12:59:31 +0100 Subject: [PATCH 5/5] Remove possible ref-tags from raw param values in CountryListEntrys Explicit conversion to str for better readability --- countrylist.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/countrylist.py b/countrylist.py index 0926693..0a14a61 100644 --- a/countrylist.py +++ b/countrylist.py @@ -238,7 +238,15 @@ class CountryList(): If param is not present raise Error """ if self.entry.has( "Chartein" ): - self._chartein_raw = self.entry.get("Chartein").value.strip() + self._chartein_raw = self.entry.get("Chartein").value + + # Remove possible ref-tags + for ref in self._chartein_raw.ifilter_tags(matches="ref"): + self._chartein_raw.remove( ref ) + + # Remove whitespace + self._chartein_raw = str(self._chartein_raw).strip() + else: raise CountryListEntryError( "Template Parameter 'Chartein' is \ missing!" ) @@ -264,7 +272,14 @@ missing!" ) If param is not present raise Error """ if self.entry.has( "Titel" ): - self._titel_raw = self.entry.get("Titel").value.strip() + self._titel_raw = self.entry.get("Titel").value + + # Remove possible ref-tags + for ref in self._titel_raw.ifilter_tags(matches="ref"): + self._titel_raw.remove( ref ) + + # Remove whitespace + self._titel_raw = str(self._titel_raw).strip() else: raise CountryListEntryError( "Template Parameter 'Titel' is \ missing!" ) @@ -329,7 +344,14 @@ missing!" ) If param is not present raise Error """ if self.entry.has( "Interpret" ): - self._interpret_raw = self.entry.get("Interpret").value.strip() + self._interpret_raw = self.entry.get("Interpret").value + + # Remove possible ref-tags + for ref in self._interpret_raw.ifilter_tags(matches="ref"): + self._interpret_raw.remove( ref ) + + # Remove whitespace + self._interpret_raw = str(self._interpret_raw).strip() else: raise CountryListEntryError( "Template Parameter 'Interpret' is \ missing!" )