当前位置: 首页>>代码示例>>Python>>正文


Python pywikibot.setAction函数代码示例

本文整理汇总了Python中pywikibot.setAction函数的典型用法代码示例。如果您正苦于以下问题:Python setAction函数的具体用法?Python setAction怎么用?Python setAction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setAction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的pywikibot.setAction函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。