From 2c81bd3d11576b407a53b37bc71042180eb3d798 Mon Sep 17 00:00:00 2001 From: magnus <magnus@fsmpi.rwth-aachen.de> Date: Fri, 29 Jul 2022 14:36:36 +0200 Subject: [PATCH] add function to get pagenames without namespace --- wikibot.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wikibot.py b/wikibot.py index 5b66fd1..1029850 100644 --- a/wikibot.py +++ b/wikibot.py @@ -5,6 +5,17 @@ import re import datetime +def strip_namespace(full_name): + """Returns the pure pagename without namespace + If a namespace withoput pagename is given like "n1:n2:" then the last namespace is returned + """ + split = full_name.split(":") + if len(split) > 1 and split[-1] == "": + return split[-2] + else: + return split[-1] + + def move_page(original_page, new_page, delete=False): """Moves a page, updates link to new page and flags or deletes the old one""" with Proxy(config.WIKI_API_URL) as proxy: @@ -37,7 +48,7 @@ def move_pages(original_name_regex, new_name_func, delete=False): page_content = proxy.wiki.getPage(old) proxy.wiki.putPage(new, page_content, {"sum": "Moved from " + old}) # bulk update for links # - update_backlink_sites = {} + update_backlink_sites = {} for page in update_pages.keys(): for link in proxy.wiki.getBackLinks(page): if update_backlink_sites.get(link): -- GitLab