From 34e7e0d3beb7b00f0c2408aabac415df49061e36 Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Sat, 11 Mar 2017 12:19:29 +0100 Subject: [PATCH] Prevent index Error if no template in leadsec Check if there is a template in leadsec before accessing list item to prevent IndexErrors Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=115 FS#115] --- bots/markpages.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bots/markpages.py b/bots/markpages.py index 23a6aa2..268d2a6 100644 --- a/bots/markpages.py +++ b/bots/markpages.py @@ -214,11 +214,12 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() # There is none on empty pages, so we need to check if leadsec: # Get the last template in leadsec - ltemplate = leadsec.filter_templates()[-1] + ltemplates = leadsec.filter_templates() # If there is one, add notice after this - if ltemplate: - self.current_wikicode.insert_after(ltemplate, self.disc_notice) + if ltemplates: + self.current_wikicode.insert_after( ltemplates[-1], + self.disc_notice ) # To have it in its own line we need to add a linbreak before self.current_wikicode.insert_before(self.disc_notice, "\n" )