This is an old revision of this page, as edited by MZMcBride (talk | contribs) at 03:32, 13 January 2014 (updated page). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Revision as of 03:32, 13 January 2014 by MZMcBride (talk | contribs) (updated page)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)mzmcbride@willow:~$ cat scripts/misc/articlecount.py
#! /usr/bin/env python # Copyright 2010 bjweeks, MZMcBride # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import datetime import MySQLdb import re import wikitools import settings report_title = 'Misplaced Pages:List of Wikipedians by article count/Data' report_template = u'''\ {| class="wikitable sortable" |- style="white-space:nowrap;" ! No. ! User ! Article count |- %s |} ''' wiki = wikitools.Wiki() wiki.login(settings.username, settings.password) conn = MySQLdb.connect(host=settings.host, db=settings.dbname, read_default_file='~/.my.cnf') cursor = conn.cursor() cursor.execute(''' /* articlecount.py SLOW_OK */ SELECT p2.page_creator, COUNT(*) FROM enwiki_p.page AS p1 JOIN u_mzmcbride_enwiki_page_creators_p.page AS p2 ON p1.page_id = p2.page_id AND p1.page_namespace = 0 AND p1.page_is_redirect = 0 GROUP BY p2.page_creator ORDER BY COUNT(*) DESC LIMIT 3000; ''') def thous(x): # From http://code.activestate.com/recipes/498181/ return re.sub(r'(\d{3})(?=\d)', r'\1,', str(x)) i = 1 output = for row in cursor.fetchall(): page_creator = u'%s' % unicode(row, 'utf-8') article_count = thous(str(row)) table_row = u'''| %d | %s | %s |-''' % (i, page_creator, article_count) output.append(table_row) i += 1 report = wikitools.Page(wiki, report_title) report_text = report_template % ('\n'.join(output)) report_text = report_text.encode('utf-8') report.edit(report_text, summary=settings.editsumm, bot=1) cursor.close() conn.close()