Wikipedia:Database reports/User preferences/Configuration

userprefs.py

#! /usr/bin/env python
# Public domain; MZMcBride; 2011

import oursql
import wikitools

import settings

report_title = settings.rootpage + 'User preferences'

report_template = u'''\
User preferences statistics; data as of <onlyinclude>~~~~~</onlyinclude>.

== Gender ==
{| class="wikitable sortable plainlinks" style="width:80%%;"
|- style="white-space:nowrap;"
! Gender
! Users
|-
%s
|}

== Language ==
{| class="wikitable sortable plainlinks" style="width:80%%;"
|- style="white-space:nowrap;"
! Language code
! Language name
! Users
|-
%s
|}

== Skin ==
{| class="wikitable sortable plainlinks" style="width:80%%;"
|- style="white-space:nowrap;"
! Skin
! Users
|-
%s
|}

== Gadgets ==
{| class="wikitable sortable plainlinks" style="width:80%%;"
|- style="white-space:nowrap;"
! Gadget
! Users
|-
%s
|}
'''

wiki = wikitools.Wiki(settings.apiurl)
wiki.login(settings.username, settings.password)

conn = oursql.connect(
    host=settings.host,
    db=settings.dbname,
    read_default_file='~/.my.cnf'
)
cursor = conn.cursor()

gender_output = []
gendered_users = 0
cursor.execute('''
/* userprefs.py SLOW_OK */
SELECT
  up_value,
  COUNT(*)
FROM user_properties
WHERE up_property = 'gender'
GROUP BY up_value;
''')
for row in cursor.fetchall():
    up_value = '{{MediaWiki:gender-%s}}' % row[0]
    count = row[1]
    gendered_users += int(row[1])
    table_row = u'''\
| %s
| %s
|-''' % (up_value, count)
    gender_output.append(table_row)

cursor.execute('''
/* userprefs.py SLOW_OK */
SELECT
  COUNT(*)
FROM user;
''')
all_users = int(cursor.fetchone()[0])
gender_output.append(u'''\
| Undeclared edits wiki pages
| %d
|-''' % (all_users - gendered_users))

language_output = []
cursor.execute('''
/* userprefs.py SLOW_OK */
SELECT
  up_value,
  COUNT(*)
FROM user_properties_anon
WHERE up_property = 'language'
GROUP BY up_value;
''')
for row in cursor.fetchall():
    lang_code = row[0]
    lang_name = '{{#language:%s}}' % row[0]
    count = row[1]
    table_row = u'''\
| %s
| %s
| %s
|-''' % (lang_code, lang_name, count)
    language_output.append(table_row)

skin_output = []
cursor.execute('''
/* userprefs.py SLOW_OK */
SELECT
  up_value,
  COUNT(*)
FROM user_properties_anon
WHERE up_property = 'skin'
GROUP BY up_value;
''')
for row in cursor.fetchall():
    up_value = '{{MediaWiki:skinname-%s}}' % row[0]
    count = row[1]
    table_row = u'''\
| %s
| %s
|-''' % (up_value, count)
    skin_output.append(table_row)

gadgets_output = []
cursor.execute('''
/* userprefs.py SLOW_OK */
SELECT
  up_property,
  COUNT(*)
FROM user_properties_anon
WHERE up_property LIKE 'gadget-%%'
AND up_value = '1'
GROUP BY up_property;
''')
for row in cursor.fetchall():
    up_property = '[[MediaWiki:%s|%s]]' % (row[0], row[0].split('gadget-', 1)[1])
    count = row[1]
    table_row = u'''\
| %s
| %s
|-''' % (up_property, count)
    gadgets_output.append(table_row)

report = wikitools.Page(wiki, report_title)
report_text = report_template % ('\n'.join(gender_output),
                                 '\n'.join(language_output),
                                 '\n'.join(skin_output),
                                 '\n'.join(gadgets_output))
report_text = report_text.encode('utf-8')
report.edit(report_text, summary=settings.editsumm, bot=1)

cursor.close()
conn.close()

crontab

0 22 * * 4 PYTHONPATH=$HOME/scripts python $HOME/scripts/database-reports/userprefs.py > /dev/null

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.