User:YiFeiBot/wikiindex size.py: Difference between revisions

Jump to navigation Jump to search
Update -- somehow not working in date
m (Zhuyifei1999 moved page User:YiFeiBot/wikiindex-size.py to User:YiFeiBot/wikiindex size.py: File remamed because of the fail of importing)
(Update -- somehow not working in date)
Line 29: Line 29:
     # script (i.e. wikiindex-size.py in this case)
     # script (i.e. wikiindex-size.py in this case)


     def __init__(self, generator, summary):
     def __init__(self, generator, summary, debug):
         """
         """
         Constructor. Parameters:
         Constructor. Parameters:
Line 46: Line 46:
         else:
         else:
             self.summary = i18n.twtranslate(self.site, 'basic-changing')
             self.summary = i18n.twtranslate(self.site, 'basic-changing')
        if debug:
            self.debug = debug
        else:
            self.debug = True


     def run(self):
     def run(self):
Line 60: Line 64:


         newtext = text
         newtext = text
          
         size_r = None
         size_r = re.compile(ur"""(?im)(?P<all>\{\{\s*Size\s*((\s*\|\s*(?P<pages>pages|wiki[ _]pages)\s*=\s*(?P<pages_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<pagesurl>statistics[ _]URL|wiki[ _]statistics[ _]URL)\s*=\s*(?P<pagesurl_value>https?://[^ \|\}\<]*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactor>wikiFactor)\s*=\s*(?P<wikifactor_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactorurl>wikiFactor[ _]URL)\s*=\s*(?P<wikifactorurl_value>http://[^ \|\}\<]*)\s*[^\|\}]*\s*))+\s*\|?\s*\}\}(\(As of (?P<day>[1-31]) (?P<month>(?=January|February|March|April|May|June|July|August|September|October|November|December)) (?P<year>[0-9][0-9][0-9][0-9])\)+\s*\|?\s*)*)""")
         size_r = re.compile(ur"""(?P<all>\{\{\s*Size\s*((\|\s*(?P<pages>pages|wiki[ _]pages)\s*=\s*(?P<pages_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<pagesurl>statistics[ _]URL|wiki[ _]statistics[ _]URL)\s*=\s*(?P<pagesurl_value>https?://[^ \|\}\<]*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactor>wikiFactor)\s*=\s*(?P<wikifactor_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactorurl>wikiFactor[ _]URL)\s*=\s*(?P<wikifactorurl_value>http://[^ \|\}\<]*)\s*[^\|\}]*\s*))+\s*\|?\s*\}\}((\s*\([Aa]s\s*of:?\s*(?P<day>\d*) (?P<month>(?=January|February|March|April|May|June|July|August|September|October|November|December)*\s*) (?P<year>\d*)\))\s*)*)""")


         wtext = page.get()
         wtext = page.get()
Line 79: Line 83:
             wikifactor_value = i.group('wikifactor_value') and i.group('wikifactor_value').strip() or ''
             wikifactor_value = i.group('wikifactor_value') and i.group('wikifactor_value').strip() or ''
             wikifactorurl_value = i.group('wikifactorurl_value') and i.group('wikifactorurl_value').strip() or ''
             wikifactorurl_value = i.group('wikifactorurl_value') and i.group('wikifactorurl_value').strip() or ''
            time_all = i.group('all') and i.group('all').strip() or ''
             day = i.group('day') and i.group('day').strip() or ''
             day = i.group('day') and i.group('day').strip() or ''
             month = i.group('month') and i.group('month').strip() or ''
             month = i.group('month') and i.group('month').strip() or ''
             year = i.group('year') and i.group('year').strip() or ''
             year = i.group('year') and i.group('year').strip() or ''
              
              
            if self.debug:
                pywikibot.output(u"text = %s" % text)
                pywikibot.output(u"all = %s" % all)
                pywikibot.output(u"pages = %s" % pages)
                pywikibot.output(u"pagesurl = %s" % pagesurl)
                pywikibot.output(u"wikifactor = %s" % wikifactor)
                pywikibot.output(u"wikifactorurl = %s" % wikifactorurl)
                pywikibot.output(u"pages_value = %s" % pages_value)
                pywikibot.output(u"pagesurl_value = %s" % pagesurl_value)
                pywikibot.output(u"wikifactor_value = %s" % wikifactor_value)
                pywikibot.output(u"wikifactorurl_value = %s" % wikifactorurl_value)
                pywikibot.output(u"day = %s" % day)
                pywikibot.output(u"month = %s" % month)
                pywikibot.output(u"year = %s" % year)
             #get new values
             #get new values
             n = re.findall(ur"(https?://[^\|\}\]]+\?action=raw|https?://[^\|\}\]]+:Statistics)", pagesurl_value)
             n = re.findall(ur"(https?://[^\|\}\]]+\?action=raw|https?://[^\|\}\]]+:Statistics)", pagesurl_value)
Line 100: Line 118:
                 if o:
                 if o:
                     if o[0] and int(pages_value) != int(o[0]):
                     if o[0] and int(pages_value) != int(o[0]):
                         comment = u"Robot: Updating size: %s -> %s" %    (pages_value, o[0])
                         self.summary = u"Robot: Updating size: %s -> %s" %    (pages_value, o[0])
                         pages_value = o[0]
                         pages_value = o[0]
                         newtime = True
                         newtime = True
Line 127: Line 145:
                 year = dt.strftime('%Y')
                 year = dt.strftime('%Y')
                  
                  
             newvalues = u"""{{Size <!--see Template:Size for full     detail-->
             newvalues = u"""{{Size <!--see Template:Size for full detail-->
| %s = %s <!--type the plain number of pages - NO thousands separators-->
| %s = %s <!--type the plain number of pages - NO thousands separators-->
| %s = %s <!--page count source (often a 'Statistics' page); if unknown type 'No'-->
| %s = %s <!--page count source (often a 'Statistics' page); if unknown type 'No'-->
Line 134: Line 152:
}}(As of: %s %s %s)<!--manually add/amend date when stats are verified and/or updated-->""" % (pages and pages or 'pages', pages_value and pages_value or '', pagesurl and pagesurl or 'statistics URL', pagesurl_value and pagesurl_value or '', wikifactor and wikifactor or 'wikiFactor', wikifactor_value and wikifactor_value or '', wikifactorurl and wikifactorurl or 'wikiFactor URL',  wikifactorurl_value and wikifactorurl_value or '', day and day or '', month and month or '', year and year or '')
}}(As of: %s %s %s)<!--manually add/amend date when stats are verified and/or updated-->""" % (pages and pages or 'pages', pages_value and pages_value or '', pagesurl and pagesurl or 'statistics URL', pagesurl_value and pagesurl_value or '', wikifactor and wikifactor or 'wikiFactor', wikifactor_value and wikifactor_value or '', wikifactorurl and wikifactorurl or 'wikiFactor URL',  wikifactorurl_value and wikifactorurl_value or '', day and day or '', month and month or '', year and year or '')
             newtext = text.replace(all, newvalues)
             newtext = text.replace(all, newvalues)
          
          
         if not self.save(newtext, page, self.summary):
         if not self.save(newtext, page, self.summary):
Line 334: Line 351:
     # summary message
     # summary message
     editSummary = ''
     editSummary = ''
    debug = False
     start = "!"
     start = "!"


Line 342: Line 360:
         elif arg.startswith('-start:'):
         elif arg.startswith('-start:'):
             start = arg[7:]
             start = arg[7:]
        elif arg == '-debug':
            debug = True
         else:
         else:
             pywikibot.output(u'Unknown argument: %s' % arg)
             pywikibot.output(u'Unknown argument: %s' % arg)
Line 354: Line 374:
         # pages from the wiki simultaneously.
         # pages from the wiki simultaneously.
         gen = pagegenerators.PreloadingGenerator(gen)
         gen = pagegenerators.PreloadingGenerator(gen)
         bot = WiSizeBot(gen, editSummary)
         bot = WiSizeBot(gen, editSummary, debug)
         bot.run()
         bot.run()
     else:
     else:
checkuser, Administrators
2,635

edits

Navigation menu