本文整理汇总了Python中pywikibot.setAction函数的典型用法代码示例。如果您正苦于以下问题:Python setAction函数的具体用法?Python setAction怎么用?Python setAction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setAction函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
timeRE = re.compile('(\d\d):(\d\d), (\d\d?) (January|February|March|April|May|June|July|August|September|October|November|December) (\d\d\d\d) \((UTC|GMT)\)')
userRE = re.compile('\[\[([Uu]ser|[Bb]enutzer|[Gg]ebruiker):([^\|\]]+)[^\]]*\]\]')
linkRE = re.compile('\[\[([^\|\]:]+)[^\]]*\]\]')
emptyRE = re.compile('^===[^=]+===\s+^{\{VICs\s+^\}\}\s*', re.MULTILINE)
#galleryRE = re.compile('^\s*[Ii]mage:([^\|]+)')
galleryRE = re.compile('^\s*([Ii]mage|[Ff]ile):([^\|]+)')
viscopeRE = re.compile('^\{\{[vV]I\|(.+)\|[^\|]+\|')
scopelistRE = re.compile('\*\s*\[\[:[Ii]mage:([^\|\]]+).*\|(.+)\]\]\s*$')
userNote = {}
removeCandidates = []
tagImages = []
scopeList = []
numChanges = 0
pageName = 'Commons:Valued_image_candidates'
#
# prepare a random sample for COM:VI
#
pywikibot.setAction( "preparing a new random sample of four valued images" )
try:
connection = MySQLdb.connect(host="commonswiki.labsdb", db="commonswiki_p", read_default_file="~/replica.my.cnf" )
cursor = connection.cursor()
cursor.execute( "select page_title from templatelinks, page where tl_title='VI' and tl_namespace=10 and page_namespace=6 and page_id=tl_from order by RAND() limit 4" )
except MySQLdb.OperationalError, message:
errorMessage = "Error %d:\n%s" % (message[ 0 ], message[ 1 ] )
开发者ID:Commonists,项目名称:VICbot,代码行数:31,代码来源:vic.py
示例2: run
def run(self):
comment = i18n.twtranslate(self.site, 'noreferences-add-tag')
pywikibot.setAction(comment)
for page in self.generator:
# 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())
try:
text = page.get()
except pywikibot.NoPage:
pywikibot.output(u"Page %s does not exist?!"
% page.title(asLink=True))
continue
except pywikibot.IsRedirectPage:
pywikibot.output(u"Page %s is a redirect; skipping."
% page.title(asLink=True))
continue
except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked?!"
% page.title(asLink=True))
continue
if pywikibot.getSite().sitename() == 'wikipedia:en' and page.isIpEdit():
pywikibot.output(
u"Page %s is edited by IP. Possible vandalized" % page.title(asLink=True))
continue
if self.lacksReferences(text):
newText = self.addReferences(text)
self.save(page, newText)
开发者ID:legoktm,项目名称:pywikipedia-original,代码行数:30,代码来源:noreferences.py
示例3: setSummaryMessage
def setSummaryMessage(self, disambPage, new_targets=[], unlink=False,
dn=False):
# TODO: setSummaryMessage() in solve_disambiguation now has parameters
# new_targets and unlink. Make use of these here.
comment = pywikibot.translate(
self.mysite, self.msg) % disambPage.title()
pywikibot.setAction(comment)
开发者ID:Rodehi,项目名称:GFROS,代码行数:7,代码来源:misspelling.py
示例4: __init__
def __init__(self, page, filename, summary, dry, always):
self.page = pywikibot.Page( pywikibot.getSite(), page )
self.filename = filename
self.summary = summary
if not self.summary:
self.summary = pywikibot.translate(pywikibot.getSite(), self.msg)
pywikibot.setAction( self.summary )
开发者ID:masao,项目名称:savemlak,代码行数:7,代码来源:put.py
示例5: run
def run(self):
comment = pywikibot.translate(pywikibot.getSite(), msg)
pywikibot.setAction(comment)
for page in self.generator:
if self.done:
break
self.treat(page)
开发者ID:Rodehi,项目名称:GFROS,代码行数:8,代码来源:selflink.py
示例6: __init__
def __init__(self, page, filename, summary, overwrite):
self.page = pywikibot.Page( pywikibot.getSite(), page )
self.filename = filename
self.summary = summary
self.overwrite = overwrite
if not self.summary:
self.summary = pywikibot.translate(pywikibot.getSite(), self.msg)
pywikibot.setAction( self.summary )
开发者ID:masao,项目名称:savemlak,代码行数:8,代码来源:createpage.py
示例7: main
def main():
xmlFilename = None
always = False
ignorepdf = False
limit = None
namespaces = []
generator = None
# Process global args and prepare generator args parser
local_args = pywikibot.handleArgs()
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
if arg.startswith('-namespace:'):
try:
namespaces.append(int(arg[11:]))
except ValueError:
namespaces.append(arg[11:])
elif arg.startswith('-summary:'):
pywikibot.setAction(arg[9:])
elif arg == '-always':
always = True
elif arg == '-ignorepdf':
ignorepdf = True
elif arg.startswith('-limit:'):
limit = int(arg[7:])
elif arg.startswith('-xmlstart'):
if len(arg) == 9:
xmlStart = pywikibot.input(
u'Please enter the dumped article to start with:')
else:
xmlStart = arg[10:]
elif arg.startswith('-xml'):
if len(arg) == 4:
xmlFilename = pywikibot.input(
u'Please enter the XML dump\'s filename:')
else:
xmlFilename = arg[5:]
else:
genFactory.handleArg(arg)
if xmlFilename:
try:
xmlStart
except NameError:
xmlStart = None
generator = XmlDumpPageGenerator(xmlFilename, xmlStart, namespaces)
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
# syntax error, show help text from the top of this file
pywikibot.showHelp('reflinks')
return
generator = pagegenerators.PreloadingGenerator(generator, step=50)
generator = pagegenerators.RedirectFilterPageGenerator(generator)
bot = ReferencesRobot(generator, always, limit, ignorepdf)
bot.run()
开发者ID:blueprintmrk,项目名称:pywikibot-core,代码行数:57,代码来源:reflinks.py
示例8: run
def run(self):
# Set the edit summary message
pywikibot.setAction(i18n.twtranslate(pywikibot.getSite(),
'djvutext-creating'))
linkingPage = pywikibot.Page(pywikibot.getSite(), self.index)
self.prefix = linkingPage.title(withNamespace=False)
if self.prefix[0:6] == 'Liber:':
self.prefix = self.prefix[6:]
pywikibot.output(u"Using prefix %s" % self.prefix)
gen = self.PagesGenerator()
site = pywikibot.getSite()
self.username = config.usernames[site.family.name][site.lang]
for pageno in gen:
pywikibot.output("Processing page %d" % pageno)
self.treat(pageno)
开发者ID:Rodehi,项目名称:GFROS,代码行数:18,代码来源:djvutext.py
示例9: populateRecentlyPromoted
def populateRecentlyPromoted(self, tagImages):
"""
Adds the newly promoted VIs in [[Commons:Valued images/Recently promoted]]
Arguments :
tagImages list constructed in the main program
"""
pywikibot.setAction(u'Preparing newly promoted [[COM:VI|Valued Images]] for sorting')
recentPage = pywikibot.Page(self.site, "Commons:Valued images/Recently promoted")
try:
currentOutputText = recentPage.get(get_redirect=True)
except pywikibot.NoPage:
pywikibot.output(u"Page %s does not exist; skipping." % page.aslink())
return
except pywikibot.IsRedirectPage:
pywikibot.output(u"Page %s is a redirect; skipping." % page.aslink())
return
except:
pywikibot.output(page.aslink())
print "An unhandled exception occured, here's the traceback!"
traceback.print_exc()
return
endOfGal = currentOutputText.rfind(u'\n</gallery>')
if endOfGal < 0:
pywikibot.output(u"Gallery on page %s is malformed; skipping." % outputPage.aslink())
else:
newOutputText = currentOutputText[:endOfGal]
for image in tagImages:
newOutputText += u"\n" + image[2]
newOutputText += currentOutputText[endOfGal:]
if not self.debug:
try:
self.put(recentPage, newOutputText)
except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked; skipping." % outputPage.aslink())
except pywikibot.EditConflict:
pywikibot.output(u'Skipping %s because of edit conflict' % (outputPage.title()))
except pywikibot.SpamfilterError, error:
pywikibot.output(u'Cannot change %s because of spam blacklist entry %s' % (outputPage.title(), error.url))
开发者ID:Commonists,项目名称:VICbot,代码行数:42,代码来源:vic.py
示例10: put_report
def put_report(report, spage, action, imagecheck=True):
report = report.decode('utf-8', 'ignore')
page = pywikibot.Page(site, spage)
'''try:
html = page.get()
if len(html)==len(report): # There may be some real changes lost, but most of non-length changes are trivial shuffling
return
if imagecheck:
imgs = set(re.findall(r"File:[^\|\]]*\(jpe?g|JPE?G|og[gv]|OG[GV]|svg|SVG|tiff?|TIFF?|gif|GIF)", html))
rimgs = set(re.findall(r"File:[^\|\]]*\(jpe?g|JPE?G|og[gv]|OG[GV]|svg|SVG|tiff?|TIFF?|gif|GIF)", report))
if imgs.issubset(rimgs) and rimgs.issubset(imgs):
return
except:
pass'''
cats = [c.title() for c in page.categories()]
for cat in cats:
if not re.search(re.escape(cat), report):
report += '\n[[' + cat + ']]'
pywikibot.setAction(action)
page.put(report)
return
开发者ID:faebug,项目名称:batchuploads,代码行数:21,代码来源:reportGLAMdashboard.py
示例11: open
elif found:
record[cat_title][today] = found
self.log_text.append(
u"* [[:%s%s]]: %d found, %d moved"
% (self.catprefix, cat_title, found, moved))
counts[cat_title] = found
# do a null edit on cat
try:
cat.put(cat.get(get_redirect=True))
except:
pass
continue
cPickle.dump(record, open(datafile, "wb"), -1)
pywikibot.setAction(i18n.twtranslate(self.site.lang,
self.maint_comment))
self.log_text.sort()
problems.sort()
newredirs.sort()
self.log_page.put(u"\n==%i-%02i-%02iT%02i:%02i:%02iZ==\n"
% time.gmtime()[:6]
+ u"\n".join(self.log_text)
+ u"\n* New redirects since last report:\n"
+ u"\n".join(newredirs)
+ u"\n" + u"\n".join(problems)
+ u"\n" + self.get_log_text())
if self.edit_requests:
edit_request_page.put(self.edit_request_text
% {'itemlist':
u"\n" + u"\n".join(
(self.edit_request_item % item)
开发者ID:iamedwardshen,项目名称:pywikibot-core,代码行数:32,代码来源:category_redirect.py
示例12: run
#.........这里部分代码省略.........
if not cat.isCategoryRedirect():
self.log_text.append(u"* False positive: %s"
% cat.title(asLink=True,
textlink=True))
continue
except pywikibot.Error:
self.log_text.append(u"* Could not load %s; ignoring"
% cat.title(asLink=True, textlink=True))
continue
cat_title = cat.title(withNamespace=False)
if not self.readyToEdit(cat):
counts[cat_title] = None
self.log_text.append(u"* Skipping %s; in cooldown period."
% cat.title(asLink=True, textlink=True))
continue
dest = cat.getCategoryRedirectTarget()
if not dest.exists():
problems.append("# %s redirects to %s"
% (cat.title(asLink=True, textlink=True),
dest.title(asLink=True, textlink=True)))
# do a null edit on cat to update any special redirect
# categories this wiki might maintain
try:
cat.put(cat.get(get_redirect=True))
except:
pass
continue
if dest.isCategoryRedirect():
double = dest.getCategoryRedirectTarget()
if double == dest or double == cat:
self.log_text.append(u"* Redirect loop from %s"
% dest.title(asLink=True,
textlink=True))
# do a null edit on cat
try:
cat.put(cat.get(get_redirect=True))
except:
pass
else:
self.log_text.append(
u"* Fixed double-redirect: %s -> %s -> %s"
% (cat.title(asLink=True, textlink=True),
dest.title(asLink=True, textlink=True),
double.title(asLink=True, textlink=True)))
oldtext = cat.get(get_redirect=True)
# remove the old redirect from the old text,
# leaving behind any non-redirect text
oldtext = template_regex.sub("", oldtext)
newtext = (u"{{%(redirtemp)s|%(ncat)s}}"
% {'redirtemp': template_list[0],
'ncat': double.title(withNamespace=False)})
newtext = newtext + oldtext.strip()
try:
cat.put(newtext,
i18n.twtranslate(self.site.lang,
self.dbl_redir_comment),
minorEdit=True)
except pywikibot.Error as e:
self.log_text.append("** Failed: %s" % e)
continue
found, moved = self.move_contents(cat_title,
dest.title(withNamespace=False),
editSummary=comment)
if found is None:
self.log_text.append(
u"* [[:%s%s]]: error in move_contents"
% (self.catprefix, cat_title))
elif found:
record[cat_title][today] = found
self.log_text.append(
u"* [[:%s%s]]: %d found, %d moved"
% (self.catprefix, cat_title, found, moved))
counts[cat_title] = found
# do a null edit on cat
try:
cat.put(cat.get(get_redirect=True))
except:
pass
continue
cPickle.dump(record, open(datafile, "wb"), -1)
pywikibot.setAction(i18n.twtranslate(self.site.lang,
self.maint_comment))
self.log_text.sort()
problems.sort()
newredirs.sort()
self.log_page.put(u"\n== %i-%02i-%02iT%02i:%02i:%02iZ ==\n"
% time.gmtime()[:6]
+ u"\n".join(self.log_text)
+ u"\n* New redirects since last report:\n"
+ u"\n".join(newredirs)
+ u"\n" + u"\n".join(problems)
+ u"\n" + self.get_log_text())
if self.edit_requests:
edit_request_page.put(self.edit_request_text
% {'itemlist': u"\n" + u"\n".join(
(self.edit_request_item % item)
for item in self.edit_requests)})
开发者ID:octobertech,项目名称:pywikibot-core,代码行数:101,代码来源:category_redirect.py
示例13: len
elif arg.startswith('-exist'):
checkbroken = False
elif arg.startswith('-keepparent'):
removeparent = False
elif arg.startswith('-all'):
main = False
else:
workingcatname.append(arg)
if len(workingcatname) == 0:
workingcatname = raw_input("Which page to start with? ")
else:
workingcatname = ' '.join(workingcatname)
mysite = pywikibot.getSite()
workingcatname = unicode(workingcatname, 'utf-8')
pywikibot.setAction(i18n.twtranslate(mysite, 'makecat-create') + u' ' + workingcatname)
workingcat = pywikibot.Category(mysite,
u'%s:%s'
% (mysite.category_namespace(),
workingcatname))
filename = pywikibot.config.datafilepath('category',
workingcatname.encode('ascii', 'xmlcharrefreplace') + '_exclude.txt')
try:
f = codecs.open(filename, 'r', encoding=mysite.encoding())
for line in f.readlines():
# remove trailing newlines and carriage returns
try:
while line[-1] in ['\n', '\r']:
line = line[:-1]
except IndexError:
pass
开发者ID:octobertech,项目名称:pywikibot-core,代码行数:31,代码来源:makecat.py
示例14: dispatchRecentlyPromoted
def dispatchRecentlyPromoted(self):
"""
Takes sorted images from [[Commons:Valued images/Recently promoted]] and places them in [[Commons:Valued images by topic]]
Arguments :
"""
# Set the edit summary message
pywikibot.setAction(u'Adding recently categorized [[COM:VI|valued images]] to the [[:Category:Galleries of valued images|VI galleries]]')
pywikibot.output(u'Adding recently categorized VIs to the VI galleries')
recentPage = pywikibot.Page(self.site, u'Commons:Valued images/Recently promoted')
galleryPrefix = u'Commons:Valued images by topic/'
recentOldText = ""
recentNewText = ""
try:
recentOldText = recentPage.get(get_redirect=True)
except pywikibot.NoPage:
pywikibot.output(u"Page %s does not exist; skipping." % recentPage.aslink())
return
except pywikibot.IsRedirectPage:
pywikibot.output(u"Page %s is a redirect; skipping." % recentPage.aslink())
#The structure recording the needed moves
moveMap = {}
#Find beginning of the gallery
inGallery = False
for line in recentOldText.split('\n'):
if not inGallery:
if line == u'<gallery>':
inGallery=True
recentNewText += line + '\n'
continue
else:
recentNewText += line + '\n'
else:
if line == u'</gallery>':
inGallery=False
recentNewText += line + '\n'
continue
else:
#Here we process an image
firstPipePosition = line.find(u'|')
fileName = line[0:firstPipePosition]
caption = line[firstPipePosition + 1:]
if caption.startswith(u'{{VICbotMove|'):
#The VI is categorized already
firstPipe = caption.find(u'|')
lastPipe = caption.rfind(u'|')
endOfTemplate = caption.rfind(u'}}')
scope = caption[firstPipe+1:lastPipe]
subpage = caption[lastPipe+1:endOfTemplate]
if subpage not in moveMap.keys():
moveMap[subpage] = []
moveMap[subpage].append((fileName, scope))
else:
#The VI is not categorized
recentNewText += line + '\n'
#Add pictures in galleries
for subpage in moveMap.keys():
galleryPage = pywikibot.Page(self.site, galleryPrefix + subpage)
try:
currentGalleryText = galleryPage.get(get_redirect=True)
except pywikibot.NoPage:
pywikibot.output(u'****************************************************')
pywikibot.output(u"Page %s does not exist; skipping." % galleryPage.aslink())
pywikibot.output(u"Skipped lines:")
for pair in moveMap[subpage]:
pywikibot.output(pair[0] + u'|' + pair[1])
pywikibot.output(u'****************************************************')
continue
except pywikibot.IsRedirectPage:
pywikibot.output(u'****************************************************')
pywikibot.output(u"Page %s is a redirect; skipping." % galleryPage.aslink())
pywikibot.output(u"Skipped lines:")
for pair in moveMap[subpage]:
pywikibot.output(pair[0] + u'|' + pair[1])
pywikibot.output(u'****************************************************')
continue
endOfGal = currentGalleryText.rfind(u'\n</gallery>')
if endOfGal < 0:
pywikibot.output(u'****************************************************')
pywikibot.output(u"Gallery on page %s is malformed; skipping." % galleryPage.aslink())
pywikibot.output(u"Skipped lines:")
for pair in moveMap[subpage]:
pywikibot.output(pair[0] + u'|' + pair[1])
pywikibot.output(u'****************************************************')
continue
newGalleryText = currentGalleryText[:endOfGal]
for pair in moveMap[subpage]:
newGalleryText += u'\n' + pair[0] + u'|' + pair[1]
newGalleryText += currentGalleryText[endOfGal:]
if not self.debug:
try:
self.put(galleryPage, newGalleryText)
except pywikibot.LockedPage:
#.........这里部分代码省略.........
开发者ID:Commonists,项目名称:VICbot,代码行数:101,代码来源:vic.py
示例15: len
for searchstring in searchstrings:
scount += 1
print Fore.CYAN + "{}".format(scount), Fore.MAGENTA + "Searching", searchstring[0], Fore.WHITE
pages = site.search(searchcore + searchstring[0], namespaces=6, where="text", get_redirects=False, total=None, content=False)
count = 0
for page in pages:
count += 1
print Fore.CYAN + "{}-{}".format(scount, count), Fore.GREEN + page.title()[5:-4], Fore.WHITE
oldhtml = page.get()
html = re.sub("\{\{PD-USGov\}\}", "{{" + searchstring[1] + "}}", oldhtml)
escss = re.escape("{{" + searchstring[1] + "}}")
html = re.sub(re.escape(escss +"[\n\s]*" + escss), "{{" + searchstring[1] + "}}", html)
if len(html)!=len(oldhtml):
comments = " ".join([r[3] for r in page.getVersionHistory()])
if re.search("diffusion", comments):
print Fore.RED + "Appears to have been previously diffused", Fore.WHITE
continue
if len(searchstring)==3 and not re.search('Category:' + searchstring[2], html):
html += "\n[[Category:" + searchstring[2] + "]]"
action = "[[User:Fæ/code/PD-USGov]] diffusion '{}' → {}".format(searchstring[0], "{{" + searchstring[1] + "}}")
pywikibot.setAction(action)
ploop = 0
while ploop<100:
try:
page.put(html)
ploop = 100
except Exception as e:
ploop += 1
print Fore.CYAN, ploop, Fore.RED, str(e), Fore.WHITE
time.sleep(10 + min(170, 10*ploop))
开发者ID:faebug,项目名称:batchuploads,代码行数:30,代码来源:relicense_PD-USGov.py
示例16: main
def main():
summary_commandline, gen, template = None, None, None
namespaces, PageTitles, exceptions = [], [], []
encat, newcatfile = "", ""
autoText, autoTitle = False, False
recentcat, newcat = False, False
genFactory = pagegenerators.GeneratorFactory()
for arg in pywikibot.handleArgs():
if arg == "-autotitle":
autoTitle = True
elif arg == "-autotext":
autoText = True
elif arg.startswith("-page"):
if len(arg) == 5:
PageTitles.append(pywikibot.input(u"Which page do you want to chage?"))
else:
PageTitles.append(arg[6:])
break
elif arg.startswith("-except:"):
exceptions.append(arg[8:])
elif arg.startswith("-template:"):
template = arg[10:]
elif arg.startswith("-facat:"):
facat = arg.replace(u"Category:", u"").replace(u"category:", u"").replace(u"رده:", u"")
encat = (
englishdictionry(u"رده:" + facat[7:], fa_site, en_site)
.replace(u"Category:", u"")
.replace(u"category:", u"")
)
break
elif arg.startswith("-encat:"):
encat = arg[7:].replace(u"Category:", u"").replace(u"category:", u"").replace(u"رده:", u"")
break
elif arg.startswith("-newcatfile:"):
newcatfile = arg[12:]
break
elif arg.startswith("-recentcat"):
arg = arg.replace(":", "")
if len(arg) == 10:
genfa = pagegenerators.RecentchangesPageGenerator()
else:
genfa = pagegenerators.RecentchangesPageGenerator(number=int(arg[10:]))
genfa = pagegenerators.DuplicateFilterPageGenerator(genfa)
genfa = pagegenerators.NamespaceFilterPageGenerator(genfa, [14])
preloadingGen = pagegenerators.PreloadingGenerator(genfa, 60)
recentcat = True
break
elif arg.startswith("-newcat"):
arg = arg.replace(":", "")
if len(arg) == 7:
genfa = pagegenerators.NewpagesPageGenerator(step=100, namespaces=14)
else:
genfa = pagegenerators.NewpagesPageGenerator(step=int(arg[7:]), namespaces=14)
preloadingGen = pagegenerators.PreloadingGenerator(genfa, 60)
newcat = True
break
elif arg.startswith("-namespace:"):
namespaces.append(int(arg[11:]))
elif arg.startswith("-summary:"):
pywikibot.setAction(arg[9:])
summary_commandline = True
else:
generator = genFactory.handleArg(arg)
if generator:
gen = genFactory.getCombinedGenerator(gen)
if encat != "":
encatfalist, encatlists = encatlist(encat)
if encatlists:
for encat in encatlists:
encat = englishdictionry(encat, en_site, fa_site)
if encat:
run([encat])
if encatfalist is not False:
run(encatfalist)
if PageTitles:
pages = [pywikibot.Page(fa_site, PageTitle) for PageTitle in PageTitles]
gen = iter(pages)
if recentcat:
for workpage in preloadingGen:
workpage = workpage.title()
cat = pywikibot.Category(fa_site, workpage)
gent = pagegenerators.CategorizedPageGenerator(cat)
run(gent)
pywikibot.stopme()
sys.exit()
if newcat:
for workpage in preloadingGen:
workpage = workpage.title()
workpage = englishdictionry(workpage, fa_site, en_site)
if workpage is not False:
encatfalist, encatlists = encatlist(workpage)
if encatlists:
for encat in encatlists:
encat = englishdictionry(encat, en_site, fa_site)
if encat:
run([encat])
if encatfalist is not False:
run(encatfalist)
pywikibot.stopme()
sys.exit()
#.........这里部分代码省略.........
开发者ID:PersianWikipedia,项目名称:fawikibot,代码行数:101,代码来源:rade.py
示例17: put
def put(self, title, contents):
mysite = pywikibot.Site()
page = pywikibot.Page(mysite, title)
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u">>> \03{lightpurple}%s\03{default} <<<"
% page.title())
if self.summary:
comment = self.summary
else:
comment = pywikibot.translate(mysite, self.msg, fallback=True)
comment_top = comment + " - " + pywikibot.translate(mysite,
self.msg_top,
fallback=True)
comment_bottom = comment + " - " + pywikibot.translate(mysite,
self.msg_bottom,
fallback=True)
comment_force = "%s *** %s ***" % (comment,
pywikibot.translate(mysite,
self.msg_force,
fallback=True))
# Remove trailing newlines (cause troubles when creating redirects)
contents = re.sub('^[\r\n]*', '', contents)
if page.exists():
if self.nocontent != u'':
pagecontents = page.get()
if pagecontents.find(self.nocontent) != -1 or pagecontents.find(self.nocontent.lower()) != -1:
pywikibot.output(u'Page has %s so it is skipped' % (self.nocontent))
return
if self.append == "Top":
pywikibot.output(u"Page %s already exists, appending on top!"
% title)
contents = contents + page.get()
comment = comment_top
elif self.append == "Bottom":
pywikibot.output(u"Page %s already exists, appending on bottom!"
% title)
contents = page.get() + contents
comment = comment_bottom
elif self.force:
pywikibot.output(u"Page %s already exists, ***overwriting!"
% title)
comment = comment_force
else:
pywikibot.output(u"Page %s already exists, not adding!" % title)
return
else:
if self.autosummary:
comment = ''
pywikibot.setAction('')
try:
page.put(contents, comment=comment, minorEdit=self.minor)
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 as error:
pywikibot.output(
u'Cannot change %s because of spam blacklist entry %s'
% (title, error.url))
开发者ID:blueprintmrk,项目名称:pywikibot-core,代码行数:65,代码来源:pagefromfile.py
示例18: featuredWithInterwiki
def featuredWithInterwiki(self, fromsite, template_on_top, task,
quiet, dry=False):
tosite = self.site
if not fromsite.lang in self.cache:
self.cache[fromsite.lang] = {}
if not tosite.lang in self.cache[fromsite.lang]:
self.cache[fromsite.lang][tosite.lang] = {}
cc = self.cache[fromsite.lang][tosite.lang]
if self.getOption('nocache') is True or \
fromsite.code in self.getOption('nocache'):
cc = {}
templatelist = self.getTemplateList(tosite.code, task)
findtemplate = '(' + '|'.join(templatelist) + ')'
re_Link_FA = re.compile(ur"\{\{%s\|%s\}\}"
% (findtemplate.replace(u' ', u'[ _]'),
fromsite.code), re.IGNORECASE)
gen = self.featuredArticles(fromsite, task, cc)
gen = PreloadingGenerator(gen)
pairs = []
for a in gen:
if a.isRedirectPage():
a = a.getRedirectTarget()
if not a.exists():
pywikibot.output(u"source page doesn't exist: %s"
% a.title())
continue
atrans = self.findTranslated(a, tosite, quiet)
if not atrans:
continue
if task != 'former':
text = atrans.get()
m = re_Link_FA.search(text)
if m:
pywikibot.output(u"(already done)")
else:
# insert just before interwiki
if (not interactive or
pywikibot.input(
u'Connecting %s -> %s. Proceed? [Y/N]'
% (a.title(), atrans.title())) in ['Y', 'y']):
site = pywikibot.getSite()
comment = pywikibot.setAction(
i18n.twtranslate(site, 'featured-' + task,
{'page': unicode(a)}))
# Moving {{Link FA|xx}} to top of interwikis
if template_on_top:
# Getting the interwiki
iw = pywikibot.getLanguageLinks(text, site)
# Removing the interwiki
text = pywikibot.removeLanguageLinks(text, site)
text += u"\r\n{{%s|%s}}\r\n" % (templatelist[0],
fromsite.code)
# Adding the interwiki
text = pywikibot.replaceLanguageLinks(text,
iw, site)
# Placing {{Link FA|xx}} right next to
# corresponding interwiki
else:
text = (text[:m.end()] +
(u" {{%s|%s}}" % (templatelist[0],
fromsite.code)) +
text[m.end():])
if not dry:
try:
atrans.put(text, comment)
except pywikibot.LockedPage:
pywikibot.output(u'Page %s is locked!'
% atrans.title())
except pywikibot.PageNotSaved, e:
pywikibot.output(u"Page not saved")
cc[a.title()] = atrans.title()
else:
text = atrans.get()
m = re_Link_FA.search(text)
if m:
# insert just before interwiki
if (not interactive or
pywikibot.input(
u'Connecting %s -> %s. Proceed? [Y/N]'
% (a.title(), atrans.title())) in ['Y', 'y']):
site = pywikibot.getSite()
comment = pywikibot.setAction(
i18n.twtranslate(site, 'featured-former',
{'page': unicode(a)}))
text = re.sub(re_Link_FA, '', text)
if not dry:
try:
atrans.put(text, comment)
except pywikibot.LockedPage:
pywikibot.output(u'Page %s is locked!'
% atrans.title())
except pywikibot.PageNotSaved, e:
pywikibot.output(u"Page not saved")
else:
开发者ID:edgarskos,项目名称:pywikipedia-rewrite,代码行数:99,代码来源:featured.py
示例19: COUNT
COUNT(page_id) AS total
FROM page
INNER JOIN categorylinks AS c ON page_id=c.cl_from AND c.cl_to!="Files_from_Wellcome_Images"
INNER JOIN categorylinks AS cc on page_id=cc.cl_from AND cc.cl_to="Files_from_Wellcome_Images"
WHERE c.cl_to NOT REGEXP "Fæ|Files_from|CC-BY|Files_with|test_"
GROUP BY c.cl_to
ORDER BY COUNT(page_id) DESC
LIMIT 50;
""")
table = "{{flatlist|"
for cat, total in cursor.fetchall():
table+="\n*{{c|"+re.sub("_"," ",cat)+"}}"+" ({:,})".format(total)
table+="\n}}"
pywikibot.setAction("Update")
page = pywikibot.Page(site, "Commons:Batch_uploading/Wellcome_Images/categories")
page.put(table)
cursor.execute("""SELECT DISTINCT rev_user_text, COUNT(page_title) AS edit_count FROM categorylinks
RIGHT JOIN page ON cl_from = page_id
LEFT JOIN revision ON page_id = rev_page
WHERE page_namespace=6 AND cl_to = 'Files_from_Wellcome_Images' AND rev_user_text NOT REGEXP '[Bb]ot'
GROUP BY 1
HAVING edit_count>0
ORDER BY 2 DESC;"""
)
table = []
for userx, count in cursor.fetchall():
table.append([count, "<abbr title='{} edits to Wellcome Images'>[[User talk:".format(count) + userx + "|" +userx +"]]</abbr>"])
开发者ID:faebug,项目名称:batchuploads,代码行数:31,代码来源:reportWellcome.py
|
请发表评论