本文整理汇总了Python中wikipedia.showDiff函数的典型用法代码示例。如果您正苦于以下问题:Python showDiff函数的具体用法?Python showDiff怎么用?Python showDiff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了showDiff函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: sort_by_country_subcat
def sort_by_country_subcat(subcat, subject):
print subcat
subcat = subcat.replace('_', ' ')
subject = subject.replace('_', ' ')
if subcat.startswith(subject):
temp1 = subcat[len(subject):].lstrip()
if temp1.startswith('from'):
temp2 = temp1[len('from'):].lstrip()
elif temp1.startswith('of'):
temp2 = temp1[len('of'):].lstrip()
elif temp1.startswith('in'):
temp2 = temp1[len('in'):].lstrip()
else:
temp2 = ''
if temp2:
if temp2.startswith('the'):
country = temp2[len('the'):].lstrip()
else:
country = temp2
page = wikipedia.Page(wikipedia.getSite(), 'Category:' + subcat)
old = u'\[\[[cC]ategory:' + subject + u' by country[^\]]*\]\]'
new = u'[[Category:' + subject + u' by country|' + country + u']]'
comment = u'Sorting [[:Category:' + subject + u' by country]]'
newtext = wikipedia.replaceExcept(page.get(), old, new, [])
wikipedia.showDiff(page.get(), newtext)
page.put(newtext, comment)
开发者ID:multichill,项目名称:toollabs,代码行数:26,代码来源:sort_by_country_category.py
示例2: updateInterwiki
def updateInterwiki (self, wikipediaPage = None, commonsPage = None):
'''
Update the interwiki's at commons from a wikipedia page. The bot just
replaces the interwiki links at the commons page with the interwiki's from
the wikipedia page. This should probably be more intelligent. We could use
add all the interwiki's and remove duplicates. Or only remove language links
if multiple language links to the same language exist.
This function is disabled for the moment untill i figure out what the best
way is to update the interwiki's.
'''
interwikis = {}
comment= u''
interwikilist = wikipediaPage.interwiki()
interwikilist.append(wikipediaPage)
for interwikiPage in interwikilist:
interwikis[interwikiPage.site()]=interwikiPage
oldtext = commonsPage.get()
# The commonssite object doesnt work with interwiki's
newtext = pywikibot.replaceLanguageLinks(oldtext, interwikis,
pywikibot.getSite(u'nl'))
comment = u'Updating interwiki\'s from [[' + \
wikipediaPage.site().language() + \
u':' + wikipediaPage.title() + u']]'
if newtext != oldtext:
#This doesnt seem to work. Newtext has some trailing whitespace
pywikibot.showDiff(oldtext, newtext)
commonsPage.put(newtext=newtext, comment=comment)
开发者ID:electionr,项目名称:rootstriker-fec-bot,代码行数:30,代码来源:commonscat.py
示例3: revert
def revert(self, item):
predata = {
'action': 'query',
'titles': item['title'],
'prop': 'revisions',
'rvprop': 'ids|timestamp|user|content',
'rvlimit': '2',
'rvstart': item['timestamp'],
}
data = query.GetData(predata, self.site)
if 'error' in data:
raise RuntimeError(data['error'])
pages = data['query'].get('pages', ())
if not pages: return False
page = pages.itervalues().next()
if len(page.get('revisions', ())) != 2: return False
rev = page['revisions'][1]
comment = u'Reverted to revision %s by %s on %s' % (rev['revid'],
rev['user'], rev['timestamp'])
if self.comment: comment += ': ' + self.comment
page = pywikibot.Page(self.site, item['title'])
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.aslink(True, True))
old = page.get()
new = rev['*']
pywikibot.showDiff(old, new)
page.put(new, comment)
return comment
开发者ID:electionr,项目名称:rootstriker-fec-bot,代码行数:32,代码来源:revertbot.py
示例4: tagNowCommons
def tagNowCommons(wImage, cImage, timestamp):
site = wikipedia.getSite()
language = site.language()
family = site.family.name
imagepage = wikipedia.ImagePage(wikipedia.getSite(), wImage)
if not imagepage.exists() or imagepage.isRedirectPage():
return
if skips.get(family) and skips.get(family).get(language):
localskips = skips.get(family).get(language)
else:
localskips = skips.get('_default')
for template in imagepage.templates():
title = template.replace(u'_', u' ').strip()
if title in localskips:
return
text = imagepage.get()
oldtext = text
text = u'{{NowCommons|File:%s|date=%s|bot=~~~}}\n' % (cImage.replace(u'_', u' '), timestamp) + text
comment = u'File is available on Wikimedia Commons.'
wikipedia.showDiff(oldtext, text)
try:
imagepage.put(text, comment)
#print u'put'
except wikipedia.LockedPage:
return
开发者ID:multichill,项目名称:toollabs,代码行数:29,代码来源:tag_nowcommons.py
示例5: tagNowcommons
def tagNowcommons(self, imagepage, filename):
""" Tagged the imag which has been moved to Commons for deletion. """
if pywikibot.Page(pywikibot.getSite('commons', 'commons'),
u'File:' + filename).exists():
# Get a fresh copy, force to get the page so we dont run into edit
# conflicts
imtxt = imagepage.get(force=True)
# Remove the move to commons templates
if imagepage.site().language() in moveToCommonsTemplate:
for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
imtxt = re.sub(u'(?i)\{\{' + moveTemplate +
u'[^\}]*\}\}', u'', imtxt)
# add {{NowCommons}}
if imagepage.site().language() in nowCommonsTemplate:
addTemplate = nowCommonsTemplate[
imagepage.site().language()] % filename
else:
addTemplate = nowCommonsTemplate['_default'] % filename
commentText = i18n.twtranslate(
imagepage.site(), 'commons-file-now-available',
{'localfile': imagepage.title(withNamespace=False),
'commonsfile': filename})
pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
imagepage.put(imtxt + addTemplate, comment=commentText)
开发者ID:Rodehi,项目名称:GFROS,代码行数:28,代码来源:imagecopy_self.py
示例6: workon
def workon(page):
mysite = wikipedia.getSite()
try:
text = page.get()
except wikipedia.IsRedirectPage:
wikipedia.output(u'%s is a redirect page. Skipping' % page.aslink())
return
except wikipedia.NoPage:
wikipedia.output(u'%s does not exist. Skipping' % page.aslink())
return
wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
links = page.linkedPages()
if len(links) > 0:
wikipedia.getall(mysite,links)
else:
wikipedia.output('Nothing left to do.')
return
for page2 in links:
try:
target = page2.getRedirectTarget()
except (wikipedia.Error,wikipedia.SectionError):
continue
text = treat(text, page2, target)
if text != page.get():
comment = wikipedia.translate(mysite, msg)
wikipedia.showDiff(page.get() ,text)
try:
page.put(text, comment)
except (wikipedia.Error):
wikipedia.output('Error: unable to put %s' % page.aslink())
开发者ID:yknip1207,项目名称:genewiki,代码行数:31,代码来源:fixing_redirects.py
示例7: process_article
def process_article(page, tag):
EditMsg = "Robot: Tagging {{Film|%s}}" %tag
wikipedia.setAction(EditMsg)
try:
wikitext = page.get()
except wikipedia.NoPage:
page.put("{{Film|%s}}" %tag)
return
except wikipedia.IsRedirectPage:
return
if re.search(tag,wikitext,re.I):
print "Skipping " + str(page)
return
# Fix Casing (Reduces the number of possible expressions)
wikitext = re.compile(r'\{\{\s*(template:|)film', re.IGNORECASE).sub(r'{{Film', wikitext)
state0 = wikitext
# Add tf parameter
wikitext = re.compile(r'\{\{\s*film(.*?)\}\}', re.IGNORECASE).sub(r'{{Film\1|%s}}' %tag, wikitext)
wikipedia.showDiff(state0, wikitext)
if (wikitext != state0):
try:
print 'Going to edit %s' %str(page)
wikipedia.output(u'WRITE: Adding %s bytes.' % str(len(wikitext)-len(state0)))
page.put(wikitext)
except KeyboardInterrupt:
sys.exit()
开发者ID:edgarskos,项目名称:legobot-old,代码行数:29,代码来源:WPFilmtf.py
示例8: fes
def fes(pagina):
pag = wikipedia.Page(wikipedia.getSite('ca'), pagina) # creem un objecte page on poder treballar
noutext = text = pag.get() # obtenuim el text
noutext = re.sub(u"\| ?pàgines ?= p\.?", "|pàgines=", text)
wikipedia.showDiff(text, noutext)
if raw_input(u"Vols penjar la pàgina [y/n]?") == "y":
pag.put(noutext, comment=u"Robot fent canvis per la {{tl|ref-llibre}}")
开发者ID:nkesquerda,项目名称:Bot_pp,代码行数:7,代码来源:bot_pp.py
示例9: tagNowcommons
def tagNowcommons(self, imagepage, filename):
'''
Tagged the imag which has been moved to Commons for deletion.
'''
if pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename).exists():
#Get a fresh copy, force to get the page so we dont run into edit conflicts
imtxt=imagepage.get(force=True)
#Remove the move to commons templates
if imagepage.site().language() in moveToCommonsTemplate:
for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
imtxt = re.sub(u'(?i)\{\{' + moveTemplate + u'[^\}]*\}\}', u'', imtxt)
#add {{NowCommons}}
if imagepage.site().language() in nowCommonsTemplate:
addTemplate = nowCommonsTemplate[imagepage.site().language()] % filename
else:
addTemplate = nowCommonsTemplate['_default'] % filename
if imagepage.site().language() in nowCommonsMessage:
commentText = nowCommonsMessage[imagepage.site().language()]
else:
commentText = nowCommonsMessage['_default']
pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
imagepage.put(imtxt + addTemplate, comment = commentText)
开发者ID:electionr,项目名称:rootstriker-fec-bot,代码行数:26,代码来源:imagecopy_self.py
示例10: addCoords
def addCoords(sourceWiki, lang, article, lat, lon, region, type, dim):
'''
Add the coordinates to article.
'''
if (article and lang and type):
coordTemplate = 'Coordinate'
site = wikipedia.getSite(lang, 'wikipedia')
page = wikipedia.Page(site, article)
try:
text = page.get()
except wikipedia.NoPage: # First except, prevent empty pages
logging.warning('Page empty: %s', article)
return False
except wikipedia.IsRedirectPage: # second except, prevent redirect
logging.warning('Page is redirect: %s', article)
wikipedia.output(u'%s is a redirect!' % article)
return False
except wikipedia.Error: # third exception, take the problem and print
logging.warning('Some error: %s', article)
wikipedia.output(u"Some error, skipping..")
return False
if coordTemplate in page.templates():
logging.info('Already has Coordinate template: %s', article)
return False
if 'Linn' in page.templates():
logging.info('Linn template without coords: %s', article)
return False
newtext = text
replCount = 1
coordText = u'{{Coordinate |NS=%s |EW=%s |type=%s |region=%s' % (lat, lon, type, region)
if (dim):
coordText += u' |dim=%s' % ( int(dim),)
coordText += '}}'
localCatName = wikipedia.getSite().namespace(WP_CATEGORY_NS)
catStart = r'\[\[(' + localCatName + '|Category):'
catStartPlain = u'[[' + localCatName + ':'
replacementText = u''
replacementText = coordText + '\n\n' + catStartPlain
# insert coordinate template before categories
newtext = re.sub(catStart, replacementText, newtext, replCount, flags=re.IGNORECASE)
if text != newtext:
logging.info('Adding coords to: %s', article)
comment = u'lisan artikli koordinaadid %s.wikist' % (sourceWiki)
wikipedia.showDiff(text, newtext)
modPage = wikipedia.input(u'Modify page: %s ([y]/n) ?' % (article) )
if (modPage.lower == 'y' or modPage == ''):
page.put(newtext, comment)
return True
else:
logging.info('Nothing to change: %s', article)
return False
else:
return False
开发者ID:edgarskos,项目名称:Toolserver-bots,代码行数:60,代码来源:coord_to_articles.py
示例11: tagNowcommons
def tagNowcommons(self, imagepage, filename):
"""
Tagged the imag which has been moved to Commons for deletion.
"""
if pywikibot.Page(pywikibot.getSite("commons", "commons"), u"File:" + filename).exists():
# Get a fresh copy, force to get the page so we dont run into edit conflicts
imtxt = imagepage.get(force=True)
# Remove the move to commons templates
if imagepage.site().language() in moveToCommonsTemplate:
for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
imtxt = re.sub(u"(?i)\{\{" + moveTemplate + u"[^\}]*\}\}", u"", imtxt)
# add {{NowCommons}}
if imagepage.site().language() in nowCommonsTemplate:
addTemplate = nowCommonsTemplate[imagepage.site().language()] % filename
else:
addTemplate = nowCommonsTemplate["_default"] % filename
if imagepage.site().language() in nowCommonsMessage:
commentText = nowCommonsMessage[imagepage.site().language()]
else:
commentText = nowCommonsMessage["_default"]
pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
imagepage.put(imtxt + addTemplate, comment=commentText)
开发者ID:h4ck3rm1k3,项目名称:pywikipediabot,代码行数:26,代码来源:imagecopy_enwp.py
示例12: sort_by_country_subcat
def sort_by_country_subcat(subcat, subject):
print subcat
subcat = subcat.replace("_", " ")
subject = subject.replace("_", " ")
if subcat.startswith(subject):
temp1 = subcat[len(subject) :].lstrip()
if temp1.startswith("from"):
temp2 = temp1[len("from") :].lstrip()
elif temp1.startswith("of"):
temp2 = temp1[len("of") :].lstrip()
elif temp1.startswith("in"):
temp2 = temp1[len("in") :].lstrip()
else:
temp2 = ""
if temp2:
if temp2.startswith("the"):
country = temp2[len("the") :].lstrip()
else:
country = temp2
page = wikipedia.Page(wikipedia.getSite(), "Category:" + subcat)
old = u"\[\[[cC]ategory:" + subject + u" by country[^\]]*\]\]"
new = u"[[Category:" + subject + u" by country|" + country + u"]]"
comment = u"Sorting [[:Category:" + subject + u" by country]]"
newtext = wikipedia.replaceExcept(page.get(), old, new, [])
wikipedia.showDiff(page.get(), newtext)
page.put(newtext, comment)
开发者ID:bymerej,项目名称:ts-multichill-bot,代码行数:26,代码来源:sort_by_country_category.py
示例13: revert
def revert(self, item):
predata = {
"action": "query",
"titles": item["title"],
"prop": "revisions",
"rvprop": "ids|timestamp|user|content",
"rvlimit": "2",
"rvstart": item["timestamp"],
}
data = query.GetData(predata, self.site)
if "error" in data:
raise RuntimeError(data["error"])
pages = data["query"].get("pages", ())
if not pages:
return False
page = pages.itervalues().next()
if len(page.get("revisions", ())) != 2:
return False
rev = page["revisions"][1]
comment = u"Reverted to revision %s by %s on %s" % (rev["revid"], rev["user"], rev["timestamp"])
if self.comment:
comment += ": " + self.comment
page = pywikibot.Page(self.site, item["title"])
pywikibot.output(
u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title(asLink=True, forceInterwiki=True, textlink=True)
)
old = page.get()
new = rev["*"]
pywikibot.showDiff(old, new)
page.put(new, comment)
return comment
开发者ID:hroest,项目名称:pywikibot-compat,代码行数:35,代码来源:revertbot.py
示例14: convertList
def convertList(page):
'''
Convert a list of NRHP entries. Both headers and items will be converted.
'''
wikipedia.output(u'Working on %s' % page.title())
text = page.get()
try:
newtext = convertHeaders(page, text)
newtext = convertItems(page, newtext)
except TypeError or AttributeError:
wikipedia.output(u'One of the regexes failed at %s, skipping this page' % (page.title,))
traceback.print_exc(file=sys.stdout)
time.sleep(10)
return u'Failed'
if not text==newtext:
wikipedia.showDiff(text, newtext)
comment = u'Converting list to use [[Template:NRHP header]] and [[Template:NRHP row]]'
#choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No'], ['y', 'n'], 'n')
choice = 'y'
if choice == 'y':
#DEBUG
page.put(newtext, comment)
return u'Success'
#wikipedia.output(newtext)
return u'Unchanged'
开发者ID:multichill,项目名称:toollabs,代码行数:31,代码来源:NRHP_converter.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: replaceCategory
def replaceCategory (image = None, parents = [], newcat = u''):
'''
Remove all parent categories and add newcat
'''
result = 0
newcats = []
if not newcat == u'':
currentCats = imagerecat.getCurrentCats(image)
workingCategories = currentCats
workingCategories.append(newcat)
# Adding parents if the category filter is lagging.
# The bot often works on new categories. In these cases the filter does know the parent categories
workingCategories = workingCategories + parents
for cat in imagerecat.applyAllFilters(workingCategories):
#Now remove those parents again
if cat not in parents:
newcats.append(cat)
if not(set(currentCats)==set(newcats)):
newtext = wikipedia.removeCategoryLinks(image.get(), image.site()) + u'\n'
for category in newcats:
newtext = newtext + u'[[Category:' + category + u']]\n'
comment = u'Moving image to (a subcategory of) [[Category:' + newcat + u']] and trying to filter categories'
wikipedia.output(image.title())
wikipedia.showDiff(image.get(), newtext)
image.put(newtext, comment)
result = 1
return result
开发者ID:bymerej,项目名称:ts-multichill-bot,代码行数:27,代码来源:populate_category.py
示例17: tagUncategorized
def tagUncategorized(templateTitle):
site = wikipedia.getSite()
language = site.language()
family = site.family.name
page = wikipedia.Page(wikipedia.getSite(), u'Template:%s' % (templateTitle,))
if not page.exists() or page.isRedirectPage():
return False
text = page.get()
oldtext = text
text = text + u'<noinclude>\n\n%s\n</noinclude>' % (uncategorizedTemplate.get(family).get(language), )
wikipedia.showDiff(oldtext, text)
try:
wikipedia.output(page.title())
page.put(text, editComment.get(family).get(language), maxTries=1)
except wikipedia.LockedPage:
return
except wikipedia.MaxTriesExceededError:
return
except wikipedia.EditConflict:
return
开发者ID:bymerej,项目名称:ts-multichill-bot,代码行数:25,代码来源:tag_uncategorized_templates.py
示例18: process_article
def process_article(page):
EditMsg = "Robot: Substituting {{[[Template:RS500|RS500]]}} and common fixes"
wikipedia.setAction(EditMsg)
try:
wikitext = page.get()
except wikipedia.NoPage:
return
except wikipedia.IsRedirectPage:
return
# Fix Casing (Reduces the number of possible expressions)
# Common fixes
# wikitext = commonfixes.fix(wikitext)
# State point. Count any changes as needing an update if they're after this line
state0 = wikitext
# Add |Iran=yes
wikitext = re.compile(r'\{\{\s*rs500(.*?)\}\}', re.IGNORECASE).sub(r'{{subst:RS500\1}}', wikitext)
wikipedia.showDiff(page.get(), wikitext)
if (wikitext != state0):
try:
wikipedia.output(u'WRITE: Adding %s bytes.' % str(len(wikitext)-len(page.get())))
# print 'Waiting 2.5 seconds'
# time.sleep(2.5)
page.put(wikitext)
except TypeError:
print 'Skipping TypeError'
return
开发者ID:edgarskos,项目名称:legobot-old,代码行数:28,代码来源:rs500subst.py
示例19: convertAllHTMLTables
def convertAllHTMLTables(self, text):
"""
Converts all HTML tables in text to wiki syntax.
Returns the converted text, the number of converted tables and the
number of warnings that occured.
"""
text = self.markActiveTables(text)
convertedTables = 0
warningSum = 0
warningMessages = u""
while True:
table, start, end = self.findTable(text)
if not table:
# no more HTML tables left
break
wikipedia.output(">> Table %i <<" % (convertedTables + 1))
# convert the current table
newTable, warningsThisTable, warnMsgsThisTable = self.convertTable(table)
# show the changes for this table
if not self.quietMode:
wikipedia.showDiff(table.replace("##table##", "table"), newTable)
warningSum += warningsThisTable
for msg in warnMsgsThisTable:
warningMessages += "In table %i: %s" % (convertedTables + 1, msg)
text = text[:start] + newTable + text[end:]
convertedTables += 1
wikipedia.output(warningMessages)
return text, convertedTables, warningSum
开发者ID:yknip1207,项目名称:genewiki,代码行数:32,代码来源:table2wiki.py
示例20: treat
def treat(self, page):
# Show the title of the page we're working on.
# Highlight the title in purple.
wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
try:
oldText = page.get()
# Inside image maps, don't touch selflinks, as they're used
# to create tooltip labels. See for example:
# http://de.wikipedia.org/w/index.php?title=Innenstadt_%28Bautzen%29&diff=next&oldid=35721641
if '<imagemap>' in oldText:
wikipedia.output(u'Skipping page %s because it contains an image map.' % page.aslink())
return
text = oldText
curpos = 0
while curpos < len(text):
match = self.linkR.search(text, pos = curpos)
if not match:
break
# Make sure that next time around we will not find this same hit.
curpos = match.start() + 1
text, jumpToBeginning = self.handleNextLink(page, text, match)
if jumpToBeginning:
curpos = 0
if oldText == text:
wikipedia.output(u'No changes necessary.')
else:
wikipedia.showDiff(oldText, text)
page.put_async(text)
except wikipedia.NoPage:
wikipedia.output(u"Page %s does not exist?!" % page.aslink())
except wikipedia.IsRedirectPage:
wikipedia.output(u"Page %s is a redirect; skipping." % page.aslink())
except wikipedia.LockedPage:
wikipedia.output(u"Page %s is locked?!" % page.aslink())
开发者ID:pyropeter,项目名称:PyroBot-1G,代码行数:35,代码来源:selflink.py
注:本文中的wikipedia.showDiff函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论