예제 #1
0
    def run(self):
        site = pywikibot.Site()
        page = pywikibot.Page(site, self.out)
        sign = pywikibot.Page(site, self.out + u'/امضا')
        text = u'<!-- SQL = ' + self.sql + u' -->\n'
        text += self.pref + u'\n'
        text += u'{| class="wikitable sortable"\n'
        for col in self.cols:
            text += u'!' + col + u'\n'

        conn = mysqldb.connect("fawiki.web.db.svc.wikimedia.cloud",
                               db="fawiki_p",
                               read_default_file="~/replica.my.cnf")
        cursor = conn.cursor()
        self.sql = self.sql.encode(site.encoding())
        cursor.execute(self.sql)
        results = cursor.fetchall()
        print(len(results), ' rows will be processed')

        for rowid in range(len(results)):
            row = results[rowid]
            text += u'|-\n'
            row = list(row)
            for idx in range(len(row)):
                if isinstance(row[idx], bytes):
                    row[idx] = row[idx].decode()
                row[idx] = str(row[idx])
                row[idx] = row[idx].replace('rollbacker', 'واگردان')
                row[idx] = row[idx].replace('patroller', 'گشت‌زن')
                row[idx] = row[idx].replace('eliminator', 'ویکی‌بان')
                row[idx] = row[idx].replace('sysop', 'مدیر')
                row[idx] = row[idx].replace('bureaucrat', 'دیوانسالار')
                row[idx] = row[idx].replace('Image-reviewer', 'بازبین تصاویر')
                row[idx] = row[idx].replace('templateeditor', 'ویرایشگر الگو')
                row[idx] = row[idx].replace('oversight', 'پنهانگر')
                row[idx] = row[idx].replace(',', '، ')
            if self.frmt:
                row = tuple(row)
                if '%d' in self.frmt:
                    row = (rowid + 1,) + row
                text += self.frmt % row
                text += u'\n'
            else:
                for item in row:
                    text += u'| ' + item + u'\n'
        text += u'|}'

        if not self.save(text, page, self.summary):
            pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))

        if self.sign:
            if not self.save('~~~~~', sign, self.summary):
                pywikibot.outout(u'Signature note saved in %s.' %
                                 sign.title(asLink=True))
예제 #2
0
    def run(self):
        site = pywikibot.Site()
        page = pywikibot.Page(site, self.out)
        sign = pywikibot.Page(site, self.out + u'/امضا')
        text = u'<!-- SQL = ' + self.sql + u' -->\n'
        text += self.pref + u'\n'
        text += u'{| class="wikitable sortable"\n'
        for col in self.cols:
            text += u'!' + col + u'\n'

        conn = mysqldb.connect("fawiki.labsdb", db="fawiki_p",
                               read_default_file="~/replica.my.cnf")
        cursor = conn.cursor()
        self.sql = self.sql.encode(site.encoding())
        cursor.execute(self.sql)
        results = cursor.fetchall()
        print len(results), ' rows will be processed'

        for rowid in range(len(results)):
            row = results[rowid]
            text += u'|-\n'
            row = list(row)
            for idx in range(len(row)):
                row[idx] = str(row[idx]).decode('utf-8')
                row[idx] = row[idx].replace('rollbacker', 'واگردان')
                row[idx] = row[idx].replace('patroller', 'گشت‌زن')
                row[idx] = row[idx].replace('eliminator', 'ویکی‌بان')
                row[idx] = row[idx].replace('sysop', 'مدیر')
                row[idx] = row[idx].replace('bureaucrat', 'دیوانسالار')
                row[idx] = row[idx].replace('Image-reviewer', 'بازبین تصاویر')
                row[idx] = row[idx].replace('templateeditor', 'ویرایشگر الگو')
                row[idx] = row[idx].replace('oversight', 'پنهانگر')
                row[idx] = row[idx].replace(',', '، ')
            if self.frmt:
                row = tuple(row)
                if '%d' in self.frmt:
                   row = (rowid + 1,) + row
                text += self.frmt % row
                text += u'\n'
            else:
                for item in row:
                    text += u'| ' + item + u'\n'
        text += u'|}'

        if not self.save(text, page, self.summary):
            pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))

        if self.sign:
            if not self.save('~~~~~', sign, self.summary):
                pywikibot.outout(u'Signature note saved in %s.' %
                    sign.title(asLink=True))
예제 #3
0
    def run(self):
        site = pywikibot.Site()
        page = pywikibot.Page(site, self.out)
        sign = pywikibot.Page(site, self.out + u'/امضا')
        text = u'<!-- SQL = ' + self.sql + u' -->\n'
        text += self.pref + u'\n'
        text += u'{| class="wikitable sortable"\n'
        for col in self.cols:
            text += u'!' + col + u'\n'

        conn = mysqldb.connect("fawiki.labsdb", db="fawiki_p",
                               read_default_file="~/replica.my.cnf")
        cursor = conn.cursor()
        self.sql = self.sql.encode(site.encoding())
        cursor.execute(self.sql)
        results = cursor.fetchall()
        print len(results), ' rows will be processed'

        for rowid in range(len(results)):
            row = results[rowid]
            text += u'|-\n'
            row = list(row)
            for idx in range(len(row)):
                row[idx] = str(row[idx]).decode('utf-8')
            if self.frmt:
                row = tuple(row)
                if '%d' in self.frmt:
                   row = (rowid + 1,) + row
                text += self.frmt % row
                text += u'\n'
            else:
                for item in row:
                    text += u'| ' + item + u'\n'
        text += u'|}'

        if not self.save(text, page, self.summary):
            pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))

        if self.sign:
            if not self.save('~~~~~', sign, self.summary):
                pywikibot.outout(u'Signature note saved in %s.' %
                    sign.title(asLink=True))
예제 #4
0
    def run(self):
        print("Stats bot started ...")
        print("Process number: %s" % self.sqlnum)
        pywikibot.output("Process number: %s" % self.sqlnum)
        bot_start = time.time()
        pywikibot.output("Start time: %s" %
                         time.asctime(time.gmtime(bot_start)))

        site = pywikibot.Site()
        page = pywikibot.Page(site, self.out)
        sign = pywikibot.Page(site, self.out + u'/امضا')
        text = u'<!-- SQL = ' + self.sql + u' -->\n'
        text += self.pref + u'\n'
        text += u'{| class="wikitable sortable"\n'
        for col in self.cols:
            text += u'!' + col + u'\n'
        query_start = time.time()
        conn = mysqldb.connect(host="fawiki.web.db.svc.wikimedia.cloud",
                               db="fawiki_p",
                               read_default_file="~/replica.my.cnf",
                               charset="utf8")
        cursor = conn.cursor()
        max_time = "SET SESSION MAX_STATEMENT_TIME = 60 * %d;" % (self.maxtime)
        cursor.execute(max_time)
        max_len = "SET SESSION GROUP_CONCAT_MAX_LEN = 15000;"
        cursor.execute(max_len)
        try:
            cursor.execute(self.sql)
        except Exception:
            print("Query took too long therefore StatBot was stopped!")
            return
        results = cursor.fetchall()
        query_end = time.time()
        delta = int(query_end - query_start)
        print("Query time: %d seconds" % delta)
        timer = '<!-- Query time: %d seconds -->\n' % delta
        text = timer + text
        text = u'<!-- SQL Number = ' + str(self.sqlnum) + u' -->\n' + text
        print(len(results), ' rows will be processed')

        for rowid in range(len(results)):
            row = results[rowid]
            text += u'|-\n'
            row = list(row)
            for idx in range(len(row)):
                if isinstance(row[idx], bytes):
                    try:
                        row[idx] = row[idx].decode()
                    except Exception:
                        try:
                            row[idx] = row[idx].decode()[:-1]
                        except Exception:
                            row[idx] = row[idx].decode()[:-2]

            if self.frmt:
                row = tuple(row)
                if '%d' in self.frmt:
                    row = (rowid + 1, ) + row
                text += self.frmt % row
                text += u'\n'
            else:
                for item in row:
                    text += u'| ' + item + u'\n'
        text += u'|}'
        # Convert Namespace number to their names
        for ns in page_namespace:
            text = text.replace(u'[[' + ns + u':', u'[[' + page_namespace[ns])
        for user_grp in user_groups:
            text = text.replace(u' ' + user_grp, u' ' + user_groups[user_grp])
        text = text.replace(u'||  ،',
                            u'|| ').replace(u'،   ||',
                                            u' ||').replace(u'، ،', u'،')
        if not self.save(text, page, self.summary):
            pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))

        if self.sign:
            if not self.save('~~~~~', sign, self.summary):
                pywikibot.outout(u'Signature note saved in %s.' %
                                 sign.title(asLink=True))
        bot_end = time.time()
        delta = int(bot_end - bot_start)
        print("Total time: %d seconds" % delta)
        pywikibot.output("Total time: %d seconds" % delta)
        pywikibot.output("End time: %s" % time.asctime(time.gmtime(bot_end)))
        print("Stats bot out ...")
예제 #5
0
    def run(self):
        print "Stats bot started ..."
        bot_start = timeit.timeit()

        site = pywikibot.Site()
        page = pywikibot.Page(site, self.out)
        sign = pywikibot.Page(site, self.out + u'/امضا')
        text = u'<!-- SQL = ' + self.sql + u' -->\n'
        text += self.pref + u'\n'
        text += u'{| class="wikitable sortable"\n'
        for col in self.cols:
            text += u'!' + col + u'\n'
        query_start = timeit.timeit()
        conn = mysqldb.connect("fawiki.labsdb", db="fawiki_p",
                               read_default_file="~/replica.my.cnf")
        cursor = conn.cursor()
        self.sql = self.sql.encode(site.encoding())
        cursor.execute(self.sql)
        results = cursor.fetchall()
        query_end = timeit.timeit()
        print "Query time: %f" % (1000.0 * abs(query_start - query_end))
        timer = '<!-- Query time: %f-->\n' % (1000.0 * abs(query_start - query_end))
        text = timer + text
        print len(results), ' rows will be processed'
        
        for rowid in range(len(results)):
            row = results[rowid]
            text += u'|-\n'
            row = list(row)
            for idx in range(len(row)):
                try:
                   row[idx] = str(row[idx]).decode('utf-8')
                except:
                    try:#error on cut by GROUP_CONCAT()
                       row[idx] = str(row[idx])[:-1].decode('utf-8')
                       #row[idx]=u'، [['.join(row[idx].split(u'، [[').pop())
                    except:
                        row[idx] = str(row[idx])[:-2].decode('utf-8')
                        #row[idx]=u'، [['.join(row[idx].split(u'، [[').pop())
            
            if self.frmt:
                row = tuple(row)
                if '%d' in self.frmt:
                    row = (rowid + 1,) + row
                text += self.frmt % row
                text += u'\n'
            else:
                for item in row:
                    text += u'| ' + item + u'\n'
        text += u'|}'
        #Conevrt Namespace number to text for queries like weekly-slow.py #12 and #13
        for ns in page_namespace:
            text=text.replace(u'[['+ns+u':',u'[['+page_namespace[ns])
        if not self.save(text, page, self.summary):
            pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))

        if self.sign:
            if not self.save('~~~~~', sign, self.summary):
                pywikibot.outout(u'Signature note saved in %s.' %
                                 sign.title(asLink=True))
        bot_end = timeit.timeit()
        print "Total time: %f" % (1000.0 * abs(bot_start - bot_end))
        print "Stats bot out ..."