本文整理汇总了Python中wikipedia.showDiff函数的典型用法代码示例。如果您正苦于以下问题:Python showDiff函数的具体用法?Python showDiff怎么用?Python showDiff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了showDiff函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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
示例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)
示例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())
示例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()
示例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}}")
示例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)
示例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
示例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)
示例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)
示例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
示例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'
示例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(),))