From 8a26b6d92a10c48d7b8fc8685a70d90bc7706a6b Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Fri, 25 Aug 2017 18:11:41 +0200 Subject: [PATCH] Normalize article titles with anchors In our db article titles with anchors are stored with underscores in anchor string. Therefore we need to replace spaces in anchor string given by pywikibot.Page.title(). Related Task: [FS#151](https://fs.golderweb.de/index.php?do=details&task_id=151) --- bots/markpages.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bots/markpages.py b/bots/markpages.py index 5fdd701..63f6d23 100644 --- a/bots/markpages.py +++ b/bots/markpages.py @@ -186,25 +186,32 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() # None if change was not accepted by user save_ret = self.put_current( self.new_text, summary=summary ) + # Normalize title with anchor (replace spaces in anchor) + article = self.current_page.title(withNamespace=False) + article_parts = article.split("#", 1) + if len(article_parts) == 2: + article_parts[1] = article_parts[1].replace(" ", "_") + article = "#".join(article_parts) + # Status if add_ret is None or ( add_ret and save_ret ): self.current_page.redfam.article_remove_status( "note_rej", - title=self.current_page.title(withNamespace=False)) + title=article) self.current_page.redfam.article_remove_status( "sav_err", - title=self.current_page.title(withNamespace=False)) + title=article) self.current_page.redfam.article_add_status( "marked", - title=self.current_page.title(withNamespace=False)) + title=article) elif save_ret is None: self.current_page.redfam.article_add_status( "note_rej", - title=self.current_page.title(withNamespace=False)) + title=article) else: self.current_page.redfam.article_add_status( "sav_err", - title=self.current_page.title(withNamespace=False)) + title=article) def add_disc_notice_template( self ): """