XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/169329
Change subject: [IMPROV] Use input_choice or input_yn if possible
......................................................................
[IMPROV] Use input_choice or input_yn if possible
Change-Id: I17fb04b9467acecffa98856668f4a92b81978509
---
M scripts/disambredir.py
M scripts/featured.py
2 files changed, 17 insertions(+), 19 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/29/169329/1
diff --git a/scripts/disambredir.py b/scripts/disambredir.py
index 9e30414..055db48 100644
--- a/scripts/disambredir.py
+++ b/scripts/disambredir.py
@@ -73,17 +73,13 @@
pywikibot.output(text[max(0, m.start() - context): m.start()] +
'\03{lightred}' + text[m.start(): m.end()] +
'\03{default}' + text[m.end(): m.end() + context])
- while True:
- choice = pywikibot.input(
- u"Option (N=do not change, y=change link to
\03{lightpurple}%s\03{default}, r=change and replace text, u=unlink)"
- % targetPage.title())
- try:
- choice = choice[0]
- except:
- choice = 'N'
- if choice in 'nNyYrRuU':
- break
- if choice in "nN":
+ choice = pywikibot.input_choice(
+ 'What should be done with the link?',
+ (('Do not change', 'n'), ('Change link to
\03{lightpurple}%s\03{default}' % targetPage.title(), 'y'),
+ ('Change and replace text', 'r'), ('Unlink', 'u')),
+ default='n', automatic_quit=False)
+
+ if choice == 'n':
continue
# The link looks like this:
@@ -101,11 +97,11 @@
if trailing_chars:
link_text += trailing_chars
- if choice in "uU":
+ if choice == 'u':
# unlink - we remove the section if there's any
text = text[:m.start()] + link_text + text[m.end():]
continue
- replaceit = choice in "rR"
+ replaceit = choice == 'r'
if link_text[0].isupper():
new_page_title = targetPage.title()
diff --git a/scripts/featured.py b/scripts/featured.py
index 270619c..6de45d6 100644
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -559,9 +559,10 @@
else:
# insert just before interwiki
if (not interactive or
- pywikibot.input(
- u'Connecting %s -> %s. Proceed? [Y/N]'
- % (source.title(), dest.title())) in ['Y', 'y']):
+ pywikibot.input_yn(
+ u'Connecting %s -> %s. Proceed?'
+ % (source.title(), dest.title()),
+ default=False, automatic_quit=False)):
if self.getOption('side'):
# Placing {{Link FA|xx}} right next to
# corresponding interwiki
@@ -581,9 +582,10 @@
if m2:
if (changed or # Don't force the user to say "Y" twice
not interactive or
- pywikibot.input(
- u'Connecting %s -> %s. Proceed? [Y/N]'
- % (source.title(), dest.title())) in ['Y', 'y']):
+ pywikibot.input_yn(
+ u'Connecting %s -> %s. Proceed?'
+ % (source.title(), dest.title()),
+ default=False, automatic_quit=False)):
text = re.sub(re_Link_remove, '', text)
changed = True
elif task == 'former':
--
To view, visit https://gerrit.wikimedia.org/r/169329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I17fb04b9467acecffa98856668f4a92b81978509
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits