def run(self): while True: welcomed_count = 0 if globalvar.quick and self.site.has_api(): us = [x for x in self.parseNewUserLog()] showStatus() try: userlib.getall(self.site, us) except NotImplementedError: globalvar.quick = False us = self._parseNewUserLogOld() else: us = self.parseNewUserLog() for users in us: if users.isBlocked(): showStatus(3) pywikibot.output(u'%s has been blocked!' % users.name() ) continue if 'bot' in users.groups(): showStatus(3) pywikibot.output(u'%s is a bot!' % users.name() ) continue if 'bot' in users.name().lower(): showStatus(3) pywikibot.output(u'%s might be a global bot!' % users.name() ) continue #if globalvar.offset != 0 and time.strptime(users.registrationTime(), "%Y-%m-%dT%H:%M:%SZ") >= globalvar.offset: # if users.editCount() >= globalvar.attachEditCount: showStatus(2) pywikibot.output(u'%s has enough edits to be welcomed.' % users.name() ) ustp = users.getUserTalkPage() if ustp.exists(): showStatus(3) pywikibot.output(u'%s has been already welcomed.' % users.name()) continue else: if self.badNameFilter(users.name()): self.reportBadAccount(users.name()) continue welcome_text = pywikibot.translate(self.site, netext) if globalvar.randomSign: if self.site.family != 'wikinews': welcome_text = welcome_text % choice(self.defineSign()) if self.site.family == 'wiktionary' and self.site.lang == 'it': pass else: welcome_text += timeselected elif (self.site.family != 'wikinews' and self.site.lang != 'it'): welcome_text = welcome_text % globalvar.defaultSign if self.site.lang in final_new_text_additions: welcome_text += pywikibot.translate(self.site, final_new_text_additions) welcome_comment = i18n.twtranslate(self.site, 'welcome-welcome') try: #append welcomed, welcome_count++ ustp.put(welcome_text, welcome_comment, minorEdit=False) welcomed_count += 1 self._totallyCount += 1 self.welcomed_users.append(users) except pywikibot.EditConflict: showStatus(4) pywikibot.output(u'An edit conflict has occured, skipping this user.') if globalvar.makeWelcomeLog and pywikibot.translate(self.site, logbook): showStatus(5) if welcomed_count == 1: pywikibot.output(u'One user has been welcomed.') elif welcomed_count == 0: pywikibot.output(u'No users have been welcomed.') else: pywikibot.output(u'%s users have been welcomed.' % welcomed_count ) if welcomed_count >= globalvar.dumpToLog: if self.makelogpage(self.welcomed_users): self.welcomed_users = list() welcomed_count = 0 else: continue # If we haven't to report, do nothing. else: if users.editCount() == 0: if not globalvar.quiet: showStatus(1) pywikibot.output(u'%s has no contributions.' % users.name() ) else: showStatus(1) pywikibot.output(u'%s has only %d contributions.' % (users.name(), users.editCount() ) ) # That user mustn't be welcomed. continue if globalvar.makeWelcomeLog and pywikibot.translate(self.site, logbook) and welcomed_count > 0: showStatus() if welcomed_count == 1: pywikibot.output(u'Putting the log of the latest user...') else: pywikibot.output(u'Putting the log of the latest %d users...' % welcomed_count) if self.makelogpage(self.welcomed_users): self.welcomed_users = list() else: continue self.welcomed_users = list() if hasattr(self, '_BAQueue'): showStatus() pywikibot.output("Putting bad name to report page....") self.reportBadAccount(None, final = True) try: if globalvar.recursive: showStatus() if locale.getlocale()[1]: strfstr = unicode(time.strftime(u"%d %b %Y %H:%M:%S (UTC)", time.gmtime()), locale.getlocale()[1]) else: strfstr = unicode(time.strftime(u"%d %b %Y %H:%M:%S (UTC)", time.gmtime())) pywikibot.output(u'Sleeping %d seconds before rerun. %s' % (globalvar.timeRecur, strfstr)) time.sleep(globalvar.timeRecur) else: raise KeyboardInterrupt except KeyboardInterrupt: #if globalvar.makeWelcomeLog and len(self.welcomed_users) > 0: # pywikibot.output("Update log before qutting script.") # self.makelogpage(self.welcomed_users) #if hasattr(self, '_BAQueue') and len(self._BAQueue) > 0 and globalvar.filtBadName: # self.reportBadAccount(None, final = True) break
def run(self): while True: welcomed_count = 0 if globalvar.quick and self.site.has_api(): us = [x for x in self.parseNewUserLog()] showStatus() try: userlib.getall(self.site, us) except NotImplementedError: globalvar.quick = False us = self._parseNewUserLogOld() else: us = self.parseNewUserLog() for users in us: if users.isBlocked(): showStatus(3) pywikibot.output(u'%s has been blocked!' % users.name()) continue if 'bot' in users.groups(): showStatus(3) pywikibot.output(u'%s is a bot!' % users.name()) continue if 'bot' in users.name().lower(): showStatus(3) pywikibot.output(u'%s might be a global bot!' % users.name()) continue #if globalvar.offset != 0 and time.strptime(users.registrationTime(), "%Y-%m-%dT%H:%M:%SZ") >= globalvar.offset: # if users.editCount() >= globalvar.attachEditCount: showStatus(2) pywikibot.output(u'%s has enough edits to be welcomed.' % users.name()) ustp = users.getUserTalkPage() if ustp.exists(): showStatus(3) pywikibot.output(u'%s has been already welcomed.' % users.name()) continue else: if self.badNameFilter(users.name()): self.reportBadAccount(users.name()) continue welcome_text = pywikibot.translate(self.site, netext) if globalvar.randomSign: if self.site.family != 'wikinews': welcome_text = (welcome_text % choice(self.defineSign())) if self.site.family == 'wiktionary' and \ self.site.lang == 'it': pass else: welcome_text += timeselected elif (self.site.family != 'wikinews' and self.site.lang != 'it'): welcome_text = (welcome_text % globalvar.defaultSign) if self.site.lang in final_new_text_additions: welcome_text += pywikibot.translate( self.site, final_new_text_additions) welcome_comment = i18n.twtranslate( self.site, 'welcome-welcome') try: #append welcomed, welcome_count++ ustp.put(welcome_text, welcome_comment, minorEdit=False) welcomed_count += 1 self._totallyCount += 1 self.welcomed_users.append(users) except pywikibot.EditConflict: showStatus(4) pywikibot.output(u'An edit conflict has occured, ' u'skipping this user.') if globalvar.makeWelcomeLog and \ pywikibot.translate(self.site, logbook): showStatus(5) if welcomed_count == 1: pywikibot.output(u'One user has been welcomed.') elif welcomed_count == 0: pywikibot.output(u'No users have been welcomed.') else: pywikibot.output(u'%s users have been welcomed.' % welcomed_count) if welcomed_count >= globalvar.dumpToLog: if self.makelogpage(self.welcomed_users): self.welcomed_users = list() welcomed_count = 0 else: continue # If we haven't to report, do nothing. else: if users.editCount() == 0: if not globalvar.quiet: showStatus(1) pywikibot.output(u'%s has no contributions.' % users.name()) else: showStatus(1) pywikibot.output(u'%s has only %d contributions.' % (users.name(), users.editCount())) # That user mustn't be welcomed. continue if globalvar.makeWelcomeLog and pywikibot.translate( self.site, logbook) and welcomed_count > 0: showStatus() if welcomed_count == 1: pywikibot.output(u'Putting the log of the latest user...') else: pywikibot.output( u'Putting the log of the latest %d users...' % welcomed_count) if self.makelogpage(self.welcomed_users): self.welcomed_users = list() else: continue self.welcomed_users = list() if hasattr(self, '_BAQueue'): showStatus() pywikibot.output("Putting bad name to report page....") self.reportBadAccount(None, final=True) try: if globalvar.recursive: showStatus() if locale.getlocale()[1]: strfstr = unicode( time.strftime(u"%d %b %Y %H:%M:%S (UTC)", time.gmtime()), locale.getlocale()[1]) else: strfstr = unicode( time.strftime(u"%d %b %Y %H:%M:%S (UTC)", time.gmtime())) pywikibot.output(u'Sleeping %d seconds before rerun. %s' % (globalvar.timeRecur, strfstr)) time.sleep(globalvar.timeRecur) else: raise KeyboardInterrupt except KeyboardInterrupt: #if globalvar.makeWelcomeLog and len(self.welcomed_users) > 0: # pywikibot.output("Update log before qutting script.") # self.makelogpage(self.welcomed_users) #if hasattr(self, '_BAQueue') and len(self._BAQueue) > 0 and globalvar.filtBadName: # self.reportBadAccount(None, final = True) break