jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/640327 )
Change subject: [IMPR] Ignore RuntimeError for missing 'redirects' in api
response
......................................................................
[IMPR] Ignore RuntimeError for missing 'redirects' in api response
Bug: T267567
Change-Id: I9453acbcae0bebcc41763e4150dc330b3afbe4a3
---
M scripts/fixing_redirects.py
1 file changed, 34 insertions(+), 23 deletions(-)
Approvals:
Meno25: Looks good to me, but someone else must approve
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index f29d272..83f385b 100755
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -16,6 +16,8 @@
#
import re
+from contextlib import suppress
+
import pywikibot
from pywikibot import pagegenerators
from pywikibot.bot import (SingleSiteBot, ExistingPageBot, NoRedirectPageBot,
@@ -129,36 +131,45 @@
continue
return text
+ @staticmethod
+ def get_target(page):
+ """Get the target page for a given page."""
+ target = None
+ if not page.exists():
+ with suppress(pywikibot.NoMoveTarget,
+ pywikibot.CircularRedirect,
+ pywikibot.InvalidTitle):
+ target = page.moved_target()
+ elif page.isRedirectPage():
+ try:
+ target = page.getRedirectTarget()
+ except (pywikibot.CircularRedirect,
+ pywikibot.InvalidTitle):
+ pass
+ except RuntimeError:
+ pywikibot.exception()
+ else:
+ section = target.section()
+ if section and not does_text_contain_section(target.text,
+ section):
+ pywikibot.warning(
+ 'Section #{} not found on page {}'
+ .format(section, target.title(as_link=True,
+ with_section=False)))
+ target = None
+ return target
+
def treat_page(self):
"""Change all redirects from the current page to actual links."""
links = self.current_page.linkedPages()
newtext = self.current_page.text
i = None
for i, page in enumerate(links):
- if not page.exists():
- try:
- target = page.moved_target()
- except (pywikibot.NoMoveTarget,
- pywikibot.CircularRedirect,
- pywikibot.InvalidTitle):
- continue
- elif page.isRedirectPage():
- try:
- target = page.getRedirectTarget()
- except (pywikibot.CircularRedirect,
- pywikibot.InvalidTitle):
- continue
- else:
- section = target.section()
- if section and not does_text_contain_section(target.text,
- section):
- pywikibot.warning(
- 'Section #{0} not found on page {1}'.format(
- section, target.title(as_link=True,
- with_section=False)))
- continue
- else:
+ target = self.get_target(page)
+
+ if target is None:
continue
+
# no fix to user namespaces
if target.namespace() in [2, 3] and page.namespace() not in [2, 3]:
continue
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/640327
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9453acbcae0bebcc41763e4150dc330b3afbe4a3
Gerrit-Change-Number: 640327
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Meno25 <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits