本文整理汇总了Python中wikipedia.inputChoice函数的典型用法代码示例。如果您正苦于以下问题:Python inputChoice函数的具体用法?Python inputChoice怎么用?Python inputChoice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inputChoice函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: treat
def treat(self):
page = wikipedia.Page(self.site, self.your_page)
if page.exists():
wikipedia.output(
u"\nWikitable on \03{lightpurple}%s\03{default} will be completed with:\n" % self.your_page
)
text = page.get()
newtext = self.newraw()
wikipedia.output(newtext)
choice = wikipedia.inputChoice(u"Do you want to add these on wikitable?", ["Yes", "No"], ["y", "N"], "N")
text = text[:-3] + newtext
summ = wikipedia.translate(self.site, summary_update)
if choice == "y":
try:
page.put(u"".join(text), summ)
except:
wikipedia.output(u"Impossible to edit. It may be an edit conflict... Skipping...")
else:
wikipedia.output(u"\nWikitable on \03{lightpurple}%s\03{default} will be created with:\n" % self.your_page)
newtext = self.newtable() + self.newraw()
wikipedia.output(newtext)
summ = wikipedia.translate(self.site, summary_creation)
choice = wikipedia.inputChoice(u"Do you want to accept this page creation?", ["Yes", "No"], ["y", "N"], "N")
if choice == "y":
try:
page.put(newtext, summ)
except wikipedia.LockedPage:
wikipedia.output(u"Page %s is locked; skipping." % title)
except wikipedia.EditConflict:
wikipedia.output(u"Skipping %s because of edit conflict" % title)
except wikipedia.SpamfilterError, error:
wikipedia.output(u"Cannot change %s because of spam blacklist entry %s" % (title, error.url))
开发者ID:yknip1207,项目名称:genewiki,代码行数:32,代码来源:statistics_in_wikitable.py
示例2: treat
def treat(self):
page = pywikibot.Page(self.site, self.your_page)
if page.exists():
pywikibot.output(u'\nWikitable on \03{lightpurple}%s\03{default} will be completed with:\n' % self.your_page )
text = page.get()
newtext = self.newraw()
pywikibot.output(newtext)
choice = pywikibot.inputChoice(u'Do you want to add these on wikitable?', ['Yes', 'No'], ['y', 'N'], 'N')
text = text[:-3] + newtext
summ = pywikibot.translate(self.site, summary_update)
if choice == 'y':
try:
page.put(u''.join(text), summ)
except:
pywikibot.output(u'Impossible to edit. It may be an edit conflict... Skipping...')
else:
pywikibot.output(u'\nWikitable on \03{lightpurple}%s\03{default} will be created with:\n' % self.your_page )
newtext = self.newtable()+self.newraw()
pywikibot.output(newtext)
summ = pywikibot.translate(self.site, summary_creation)
choice = pywikibot.inputChoice(u'Do you want to accept this page creation?', ['Yes', 'No'], ['y', 'N'], 'N')
if choice == 'y':
try:
page.put(newtext, summ)
except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked; skipping." % title)
except pywikibot.EditConflict:
pywikibot.output(u'Skipping %s because of edit conflict' % title)
except pywikibot.SpamfilterError, error:
pywikibot.output(u'Cannot change %s because of spam blacklist entry %s' % (title, error.url))
开发者ID:NaturalSolutions,项目名称:ecoReleve-Concepts,代码行数:30,代码来源:statistics_in_wikitable.py
示例3: treat
def treat(self, pageno):
"""
Loads the given page, does some changes, and saves it.
"""
site = pywikibot.getSite()
page_namespace = site.family.namespaces[104][site.lang]
page = pywikibot.Page(site, u'%s:%s/%d'
% (page_namespace, self.prefix, pageno))
exists = page.exists()
djvutxt = self.get_page(pageno)
if not djvutxt:
text = u'<noinclude><pagequality level="0" user="%s" /><div class="pagetext">\n\n\n</noinclude><noinclude><references/></div></noinclude>' % (self.username)
else:
text = u'<noinclude><pagequality level="1" user="%s" /><div class="pagetext">\n\n\n</noinclude>%s<noinclude><references/></div></noinclude>' % (self.username,djvutxt)
# convert to wikisyntax
# this adds a second line feed, which makes a new paragraph
text = text.replace('', "\n") # US /x1F
text = text.replace('', "\n") # GS /x1D
text = text.replace('', "\n") # FF /x0C
# only save if something was changed
# automatically ask if overwriting an existing page
ask = self.ask
if exists:
ask = True
old_text = page.get()
if old_text == text:
pywikibot.output(u"No changes were needed on %s"
% page.title(asLink=True))
return
else:
old_text = ''
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title())
pywikibot.showDiff(old_text, text)
if self.dry:
pywikibot.inputChoice(u'Dry mode... Press enter to continue', [],
[], 'dummy')
return
if ask:
choice = pywikibot.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No'], ['y', 'N'], 'N')
else:
choice = 'y'
if choice == 'y':
try:
# Save the page
page.put_async(text)
except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked; skipping."
% page.title(asLink=True))
except pywikibot.EditConflict:
pywikibot.output(u'Skipping %s because of edit conflict' % (page.title()))
except pywikibot.SpamfilterError, error:
pywikibot.output(u'Cannot change %s because of spam blacklist entry %s' % (page.title(), error.url))
开发者ID:edgarskos,项目名称:pywikipedia-git,代码行数:57,代码来源:djvutext.py
示例4: useHashGenerator
def useHashGenerator(self):
# http://toolserver.org/~multichill/nowcommons.php?language=it&page=2&filter=
lang = self.site.lang
num_page = 0
word_to_skip_translated = pywikibot.translate(self.site, word_to_skip)
images_processed = list()
while 1:
url = 'http://toolserver.org/~multichill/nowcommons.php?language=%s&page=%s&filter=' % (lang, num_page)
HTML_text = self.site.getUrl(url, no_hostname = True)
reg = r'<[Aa] href="(?P<urllocal>.*?)">(?P<imagelocal>.*?)</[Aa]> +?</td><td>\n\s*?'
reg += r'<[Aa] href="(?P<urlcommons>http://commons.wikimedia.org/.*?)">Image:(?P<imagecommons>.*?)</[Aa]> +?</td><td>'
regex = re.compile(reg, re.UNICODE)
found_something = False
change_page = True
for x in regex.finditer(HTML_text):
found_something = True
image_local = x.group('imagelocal')
image_commons = x.group('imagecommons')
if image_local in images_processed:
continue
change_page = False
images_processed.append(image_local)
# Skip images that have something in the title (useful for it.wiki)
image_to_skip = False
for word in word_to_skip_translated:
if word.lower() in image_local.lower():
image_to_skip = True
if image_to_skip:
continue
url_local = x.group('urllocal')
url_commons = x.group('urlcommons')
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% image_local)
pywikibot.output(u'Local: %s\nCommons: %s\n'
% (url_local, url_commons))
result1 = webbrowser.open(url_local, 0, 1)
result2 = webbrowser.open(url_commons, 0, 1)
if image_local.split('Image:')[1] == image_commons:
choice = pywikibot.inputChoice(
u'The local and the commons images have the same name, continue?',
['Yes', 'No'], ['y', 'N'], 'N')
else:
choice = pywikibot.inputChoice(
u'Are the two images equal?',
['Yes', 'No'], ['y', 'N'], 'N')
if choice.lower() in ['y', 'yes']:
yield [image_local, image_commons]
else:
continue
# The page is dinamically updated, so we may don't need to change it
if change_page:
num_page += 1
# If no image found means that there aren't anymore, break.
if not found_something:
break
开发者ID:Botomatik,项目名称:JackBot,代码行数:55,代码来源:nowcommons.py
示例5: process_filename
def process_filename(self):
# Isolate the pure name
filename = self.url
if '/' in filename:
filename = filename.split('/')[-1]
if '\\' in filename:
filename = filename.split('\\')[-1]
if self.urlEncoding:
filename = urllib.unquote(filename.decode(self.urlEncoding))
if self.useFilename:
filename = self.useFilename
if not self.keepFilename:
wikipedia.output(u"The filename on the target wiki will default to: %s" % filename)
# ask newfn until it's valid
ok = False
# FIXME: these 2 belong somewhere else, presumably in family
forbidden = '/' # to be extended
allowed_formats = (u'gif', u'jpg', u'jpeg', u'mid', u'midi', u'ogg', u'png', u'svg', u'xcf', u'djvu')
while not ok:
ok = True
newfn = wikipedia.input(u'Enter a better name, or press enter to accept:')
if newfn == "":
newfn = filename
ext = os.path.splitext(newfn)[1].lower().strip('.')
for c in forbidden:
if c in newfn:
print "Invalid character: %s. Please try again" % c
ok = False
if ext not in allowed_formats and ok:
choice = wikipedia.inputChoice(u"File format is not one of [%s], but %s. Continue?" % (u' '.join(allowed_formats), ext), ['yes', 'no'], ['y', 'N'], 'N')
if choice == 'n':
ok = False
if newfn != '':
filename = newfn
# MediaWiki doesn't allow spaces in the file name.
# Replace them here to avoid an extra confirmation form
filename = filename.replace(' ', '_')
# A proper description for the submission.
wikipedia.output(u"The suggested description is:")
wikipedia.output(self.description)
if self.verifyDescription:
newDescription = u''
choice = wikipedia.inputChoice(u'Do you want to change this description?', ['Yes', 'No'], ['y', 'N'], 'n')
if choice == 'y':
import editarticle
editor = editarticle.TextEditor()
newDescription = editor.edit(self.description)
# if user saved / didn't press Cancel
if newDescription:
self.description = newDescription
return filename
开发者ID:VisualEffects,项目名称:pywikia,代码行数:55,代码来源:upload.py
示例6: main
def main():
pywikibot.warning(u"This script will set preferences on all " u"configured accounts!")
pywikibot.output(
u"You have %s accounts configured." % sum([len(family) for family in config.usernames.itervalues()])
)
if pywikibot.inputChoice(u"Do you wish to continue?", ["no", "yes"], ["n", "y"], "n") == "n":
return
if (
pywikibot.inputChoice(
u"Do you already know which preference you wish " u"to set?", ["no", "yes"], ["n", "y"], "y"
)
== "n"
):
site = pywikibot.getSite()
pywikibot.output(u"Getting list of available preferences from %s." % site)
prefs = Preferences(site)
pywikibot.output(u"-" * 73)
pywikibot.output(u"| Name | Value |")
pywikibot.output(u"-" * 73)
pref_data = prefs.items()
pref_data.sort()
for key, value in pref_data:
pywikibot.output(table_cell(key, 4) + table_cell(value, 5) + "|")
pywikibot.output(u"-" * 73)
pywikibot.output(u"")
pywikibot.output(u"(For checkboxes: An empty string evaluates to False; " u"all others to True)")
pywikibot.output(u"")
while True:
keys, values = [], []
while True:
try:
keys.append(pywikibot.input(u"Which preference do you wish to set?"))
except KeyboardInterrupt:
return
values.append(pywikibot.input(u"To what value do you wish to set '%s'?" % keys[-1]))
if pywikibot.inputChoice(u"Set more preferences?", ["no", "yes"], ["n", "y"], "n") == "n":
break
if (
pywikibot.inputChoice(
u"Set %s?" % u", ".join(u"%s:%s" % (key, value) for key, value in zip(keys, values)),
["yes", "no"],
["y", "n"],
"n",
)
== "y"
):
set_all(keys, values, verbose=True)
pywikibot.output(u"Preferences have been set on all wikis.")
开发者ID:NaturalSolutions,项目名称:ecoReleve-Concepts,代码行数:54,代码来源:preferences.py
示例7: main
def main():
pywikibot.warning(u'This script will set preferences on all '
u'configured accounts!')
pywikibot.output(u'You have %s accounts configured.'
% sum([len(family)
for family in config.usernames.itervalues()]))
if pywikibot.inputChoice(u'Do you wish to continue?',
['no', 'yes'], ['n', 'y'], 'n') == 'n':
return
if pywikibot.inputChoice(u'Do you already know which preference you wish '
u'to set?', ['no', 'yes'], ['n', 'y'], 'y') == 'n':
site = pywikibot.getSite()
pywikibot.output(u'Getting list of available preferences from %s.'
% site)
prefs = Preferences(site)
pywikibot.output(u'-' * 73)
pywikibot.output(u'| Name | Value |')
pywikibot.output(u'-' * 73)
pref_data = prefs.items()
pref_data.sort()
for key, value in pref_data:
pywikibot.output(table_cell(key, 4) + table_cell(value, 5) + '|')
pywikibot.output(u'-' * 73)
pywikibot.output(u'')
pywikibot.output(u'(For checkboxes: An empty string evaluates to False; '
u'all others to True)')
pywikibot.output(u'')
while True:
keys, values = [], []
while True:
try:
keys.append(pywikibot.input(
u'Which preference do you wish to set?'))
except KeyboardInterrupt:
return
values.append(pywikibot.input(
u"To what value do you wish to set '%s'?" % keys[-1]))
if pywikibot.inputChoice(u"Set more preferences?",
['no', 'yes'], ['n', 'y'], 'n') == 'n':
break
if pywikibot.inputChoice(
u"Set %s?"
% u', '.join(u'%s:%s' % (key, value)
for key, value in zip(keys, values)),
['yes', 'no'], ['y', 'n'], 'n') == 'y':
set_all(keys, values, verbose=True)
pywikibot.output(u"Preferences have been set on all wikis.")
开发者ID:pywikibot,项目名称:compat,代码行数:53,代码来源:preferences.py
示例8: save
def save(self, text, page, comment, cleanInfobox, minorEdit=False, botflag=False):
# only save if something was changed
if text != page.get() and self.canEditPage:
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title())
# show what was changed
pywikibot.showDiff(page.get(), text)
self.log.write(comment+"\n")
self.log.write("======" + page.title() + "======\n")
self.log.write(self.logDiff(page.get(), text))
self.log.write("\n\n")
self.log.write(cleanInfobox)
self.log.write("\n\n")
if not self.html:
self.log.close()
if self.html:
self.filmLogLinks.write('<a href="https://secure.wikimedia.org/wikipedia/en/wiki/'+page.title().replace(" ", "_")+'?action=edit">'+page.title()+'</a><br />'+"\n")
elif self.dry:
spNotepad = subprocess.Popen('notepad filmLog.diff')
spChrome = subprocess.Popen(self.chrome+' '+"https://secure.wikimedia.org/wikipedia/en/wiki/"+page.title().replace(" ", "_").encode('utf-8', 'replace')+"?action=edit")
choice = pywikibot.inputChoice("This is a wait", ['Yes', 'No'], ['y', 'N'], 'N')
pywikibot.output(u'Comment: %s' %comment)
if not self.dry:
choice = pywikibot.inputChoice(
u'Do you want to accept these changes?',
['Yes', 'No'], ['y', 'N'], 'N')
if choice == 'y':
try:
# Save the page
page.put(text, comment=comment,
minorEdit=minorEdit, botflag=botflag)
except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked; skipping."
% page.title(asLink=True))
except pywikibot.EditConflict:
pywikibot.output(
u'Skipping %s because of edit conflict'
% (page.title()))
except pywikibot.SpamfilterError, error:
pywikibot.output(
u'Cannot change %s because of spam blacklist entry %s'
% (page.title(), error.url))
else:
return True
else:
spNotepad = subprocess.Popen('notepad filmLog.diff')
spChrome = subprocess.Popen(self.chrome+' '+"https://secure.wikimedia.org/wikipedia/en/wiki/"+page.title().replace(" ", "_").encode('utf-8', 'replace')+"?action=edit")
choice = pywikibot.inputChoice("This is a wait", ['Yes', 'No'], ['y', 'N'], 'N')
开发者ID:peppage,项目名称:Film-bot,代码行数:53,代码来源:Film.py
示例9: main
def main():
#page generator
gen = None
pageTitle = []
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
# to work on.
genFactory = pagegenerators.GeneratorFactory()
for arg in wikipedia.handleArgs():
if not genFactory.handleArg(arg):
pageTitle.append(arg)
# Disabled this check. Although the point is still valid, there
# is now a warning and a prompt (see below).
#if wikipedia.getSite() == wikipedia.getSite('nl','wikipedia'):
#print "Deze bot is op WikipediaNL niet gewenst."
#print "Het toevoegen van cosmetic changes bij andere wijzigingen is toegestaan,"
#print "maar cosmetic_changes als stand-alone bot niet."
#print "Zoek alstublieft een nuttig gebruik voor uw bot."
#sys.exit()
if pageTitle:
page = wikipedia.Page(wikipedia.getSite(), ' '.join(pageTitle))
gen = iter([page])
if not gen:
gen = genFactory.getCombinedGenerator()
if not gen:
wikipedia.showHelp()
elif wikipedia.inputChoice(warning + '\nDo you really want to continue?', ['yes', 'no'], ['y', 'N'], 'N') == 'y':
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = CosmeticChangesBot(preloadingGen)
bot.run()
开发者ID:pyropeter,项目名称:PyroBot-1G,代码行数:33,代码来源:cosmetic_changes.py
示例10: PickTarget
def PickTarget(self, title, original, candidates):
if len(candidates) == 0:
return None
if len(candidates) == 1:
return candidates[0]
pagesDontExist = []
pagesRedir = {}
pagesExist = []
for newTitle in candidates:
dst = self.Page(newTitle)
if not dst.exists():
pagesDontExist.append(newTitle)
elif dst.isRedirectPage():
pagesRedir[newTitle] = dst.getRedirectTarget().title()
else:
pagesExist.append(newTitle)
if len(pagesExist) == 1:
return pagesExist[0]
elif len(pagesExist) == 0 and len(pagesRedir) > 0:
if len(pagesRedir) == 1:
return pagesRedir.keys()[0]
t = None
for k, v in pagesRedir.iteritems():
if not t:
t = v # first item
elif t != v:
break
else:
# all redirects point to the same target
# pick the first one, doesn't matter what it is
return pagesRedir.keys()[0]
if not self.autonomous:
pywikibot.output(
u"Could not auto-decide for page %s. Which link should be chosen?" % self.MakeLink(title, False)
)
pywikibot.output(u"Original title: ", newline=False)
self.ColorCodeWord(original + "\n", True)
count = 1
for t in candidates:
if t in pagesDontExist:
msg = u"missing"
elif t in pagesRedir:
msg = u"Redirect to " + pagesRedir[t]
else:
msg = u"page exists"
self.ColorCodeWord(u" %d: %s (%s)\n" % (count, t, msg), True)
count += 1
answers = [str(i) for i in xrange(0, count)]
choice = int(pywikibot.inputChoice(u"Which link to choose? (0 to skip)", answers, [a[0] for a in answers]))
if choice > 0:
return candidates[choice - 1]
return None
开发者ID:NaturalSolutions,项目名称:ecoReleve-Concepts,代码行数:60,代码来源:casechecker.py
示例11: save
def save(self, text, page, comment, minorEdit=False, botflag=False):
# only save if something was changed
if text != page.get():
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title())
# show what was changed
pywikibot.showDiff(page.get(), text)
pywikibot.output(u'Comment: %s' %comment)
choice = pywikibot.inputChoice(
u'Do you want to accept these changes?',
['Yes', 'No'], ['y', 'N'], 'N')
if choice == 'y':
try:
# Save the page
page.put(text, comment=comment,
minorEdit=minorEdit, botflag=botflag)
except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked; skipping."
% page.title(asLink=True))
except pywikibot.EditConflict:
pywikibot.output(
u'Skipping %s because of edit conflict'
% (page.title()))
except pywikibot.SpamfilterError, error:
pywikibot.output(
u'Cannot change %s because of spam blacklist entry %s'
% (page.title(), error.url))
else:
return True
开发者ID:peppage,项目名称:Film-bot,代码行数:32,代码来源:createInfobox.py
示例12: main
def main():
doCount = False
argsList = []
namespaces = []
for arg in wikipedia.handleArgs():
if arg == '-count':
doCount = True
elif arg.startswith('-namespace:'):
try:
namespaces.append(int(arg[len('-namespace:'):]))
except ValueError:
namespaces.append(arg[len('-namespace:'):])
else:
argsList.append(arg)
if doCount:
robot = ReferencesRobot()
if not argsList:
argsList = templates
choice = ''
if 'reflist' in argsList:
wikipedia.output(u'NOTE: it will take a long time to count "reflist".')
choice = wikipedia.inputChoice(u'Proceed anyway?', ['yes', 'no', 'skip'], ['y', 'n', 's'], 'y')
if choice == 's':
argsList.remove('reflist')
if choice <> 'n':
robot.countRefs(argsList, namespaces)
else:
wikipedia.showHelp('refcheck')
开发者ID:VisualEffects,项目名称:pywikia,代码行数:29,代码来源:refcheck.py
示例13: treat
def treat(self, page):
try:
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
ccToolkit = CosmeticChangesToolkit(
page.site(), debug=True, namespace=page.namespace(), pageTitle=page.title()
)
changedText = ccToolkit.change(page.get())
if changedText.strip() != page.get().strip():
if not self.acceptall:
choice = pywikibot.inputChoice(
u"Do you want to accept these changes?", ["Yes", "No", "All", "Quit"], ["y", "N", "a", "q"], "N"
)
if choice == "a":
self.acceptall = True
elif choice == "q":
self.done = True
return
if self.acceptall or choice == "y":
page.put(changedText, comment=self.comment)
else:
pywikibot.output("No changes were necessary in %s" % page.title())
except pywikibot.NoPage:
pywikibot.output("Page %s does not exist?!" % page.title(asLink=True))
except pywikibot.IsRedirectPage:
pywikibot.output("Page %s is a redirect; skipping." % page.title(asLink=True))
except pywikibot.LockedPage:
pywikibot.output("Page %s is locked?!" % page.title(asLink=True))
except pywikibot.EditConflict:
pywikibot.output("An edit conflict has occured at %s." % page.title(asLink=True))
开发者ID:swertschak,项目名称:wikijournals-api,代码行数:31,代码来源:cosmetic_changes.py
示例14: appendtext
def appendtext(page, apptext):
global always
if page.isRedirectPage():
page = page.getRedirectTarget()
if not page.exists():
if page.isTalkPage():
text = u''
else:
raise pywikibot.NoPage(u"Page '%s' does not exist" % page.title())
else:
text = page.get()
# Here you can go editing. If you find you do not
# want to edit this page, just return
oldtext = text
text += apptext
if text != oldtext:
pywikibot.showDiff(oldtext, text)
if not always:
choice = pywikibot.inputChoice(
u'Do you want to accept these changes?', ['Yes', 'No', 'All'],
['y', 'N', 'a'], 'N')
if choice == 'a':
always = True
if always or choice == 'y':
page.put(text, pywikibot.translate(pywikibot.getSite(), comment))
开发者ID:legoktm,项目名称:pywikipedia-original,代码行数:25,代码来源:unusedfiles.py
示例15: save
def save(self, page, newText):
"""
Saves the page to the wiki, if the user accepts the changes made.
"""
pywikibot.showDiff(page.get(), newText)
if not self.always:
choice = pywikibot.inputChoice(
u'Do you want to accept these changes?',
['Yes', 'No', 'Always yes'], ['y', 'N', 'a'], 'Y')
if choice == 'n':
return
elif choice == 'a':
self.always = True
if self.always:
try:
page.put(newText)
except pywikibot.EditConflict:
pywikibot.output(u'Skipping %s because of edit conflict'
% (page.title(),))
except pywikibot.SpamfilterError, e:
pywikibot.output(
u'Cannot change %s because of blacklist entry %s'
% (page.title(), e.url))
except pywikibot.LockedPage:
pywikibot.output(u'Skipping %s (locked page)' % (page.title(),))
开发者ID:Protonk,项目名称:pywikipedia2,代码行数:26,代码来源:noreferences.py
示例16: treat
def treat(self, page):
try:
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
ccToolkit = CosmeticChangesToolkit(page.site(), debug = True, namespace = page.namespace(), pageTitle=page.title())
changedText = ccToolkit.change(page.get())
if changedText.strip() != page.get().strip():
if not self.acceptall:
choice = pywikibot.inputChoice(u'Do you want to accept these changes?',
['Yes', 'No', 'All', 'Quit'], ['y', 'N', 'a', 'q'], 'N')
if choice == 'a':
self.acceptall = True
elif choice == 'q':
self.done = True
return
if self.acceptall or choice == 'y':
page.put(changedText, comment=self.comment)
else:
pywikibot.output('No changes were necessary in %s' % page.title())
except pywikibot.NoPage:
pywikibot.output("Page %s does not exist?!" % page.aslink())
except pywikibot.IsRedirectPage:
pywikibot.output("Page %s is a redirect; skipping." % page.aslink())
except pywikibot.LockedPage:
pywikibot.output("Page %s is locked?!" % page.aslink())
except pywikibot.EditConflict:
pywikibot.output("An edit conflict has occured at %s." % page.aslink())
开发者ID:yknip1207,项目名称:genewiki,代码行数:28,代码来源:cosmetic_changes.py
示例17: put_page
def put_page(self, page, new):
"""
Prints diffs between orginal and new (text), puts new text for page
"""
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title())
pywikibot.showDiff(page.get(), new)
if not self.acceptall:
choice = pywikibot.inputChoice(u'Do you want to accept ' +
u'these changes?',
['Yes', 'No', 'All'],
['y', 'N', 'a'], 'N')
if choice == 'a':
self.acceptall = True
if choice == 'y':
page.put_async(new)
if self.acceptall:
try:
page.put(new)
except pywikibot.EditConflict:
pywikibot.output(u'Skipping %s because of edit conflict'
% (page.title(),))
except pywikibot.SpamfilterError, e:
pywikibot.output(
u'Cannot change %s because of blacklist entry %s'
% (page.title(), e.url))
except pywikibot.PageNotSaved, error:
pywikibot.output(u'Error putting page: %s' % (error.args,))
开发者ID:edgarskos,项目名称:pywikipedia-git,代码行数:28,代码来源:reflinks.py
示例18: run
def run(self):
for page in self.generator:
if page.isRedirectPage():
page = page.getRedirectTarget()
page_t = page.title()
# Show the title of the page we're working on.
# Highlight the title in purple.
wikipedia.output(u"\n>>> \03{lightpurple}%s\03{default} <<<"
% page_t)
page_cap = wikipedia.Page(wikipedia.getSite(), page_t.title().capitalize())
if not page_cap.exists():
wikipedia.output(u'%s doesn\'t exist' % page_cap.title())
if not self.acceptall:
choice = wikipedia.inputChoice(
u'Do you want to create a redirect?',
['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
if choice == 'a':
self.acceptall = True
if self.acceptall or choice == 'y':
try:
wikipedia.setAction(
wikipedia.translate(wikipedia.getSite(), msg)
% page_t)
page_cap.put(u"#REDIRECT [[%s]]" % page_t)
print
except:
wikipedia.output(
u"An error occurred. Retrying in 15 seconds...")
time.sleep(15)
continue
else:
wikipedia.output(u'%s already exists, skipping...\n'
% page_t.title())
开发者ID:pyropeter,项目名称:PyroBot-1G,代码行数:33,代码来源:capitalize_redirects.py
示例19: save
def save(self, page, text):
if text != page.get():
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title())
pywikibot.showDiff(page.get(), text)
if not self.always:
choice = pywikibot.inputChoice(
u'Do you want to accept these changes?',
['Yes', 'No', 'Always yes'], ['y', 'N', 'a'], 'N')
if choice == 'n':
return
elif choice == 'a':
self.always = True
if self.always:
try:
page.put(text, comment=self.comment)
except pywikibot.EditConflict:
pywikibot.output(u'Skipping %s because of edit conflict'
% (page.title(),))
except pywikibot.SpamfilterError, e:
pywikibot.output(
u'Cannot change %s because of blacklist entry %s'
% (page.title(), e.url))
except pywikibot.LockedPage:
pywikibot.output(u'Skipping %s (locked page)'
% (page.title(),))
开发者ID:SirComputer1,项目名称:SCBot,代码行数:29,代码来源:isbn.py
示例20: handleNextLink
def handleNextLink(self, text, match, context = 100):
"""
Returns a tuple (text, jumpToBeginning).
text is the unicode string after the current link has been processed.
jumpToBeginning is a boolean which specifies if the cursor position
should be reset to 0. This is required after the user has edited the
article.
"""
# ignore interwiki links and links to sections of the same page as well
# as section links
if not match.group('title') \
or self.pageToUnlink.site().isInterwikiLink(match.group('title')) \
or match.group('section'):
return text, False
linkedPage = pywikibot.Page(self.pageToUnlink.site(),
match.group('title'))
# Check whether the link found is to the current page itself.
if linkedPage != self.pageToUnlink:
# not a self-link
return text, False
else:
# at the beginning of the link, start red color.
# at the end of the link, reset the color to default
if self.always:
choice = 'a'
else:
pywikibot.output(
text[max(0, match.start() - context) : match.start()] \
+ '\03{lightred}' + text[match.start() : match.end()] \
+ '\03{default}' + text[match.end() : match.end() + context])
choice = pywikibot.inputChoice(
u'\nWhat shall be done with this link?\n',
['unlink', 'skip', 'edit', 'more context',
'unlink all', 'quit'],
['U', 's', 'e', 'm', 'a', 'q'], 'u')
pywikibot.output(u'')
if
|
请发表评论