Wikipedia:Database reports/Tiny disambiguation pages/Configuration

From Wikipedia, the free encyclopedia
#config
page_title = '%sTiny disambiguation pages'


import settings
import wikipedia
import MySQLdb
page_title=page_title%settings.rootpage 
rows=u''''''
db =  MySQLdb.connect(db=settings.dbname, host=settings.host, read_default_file="~/.my.cnf")
template = u"""
This page consists of [[WP:DISAMBIG|disambiguation]] pages that have fewer than two links to articles, templates or categories. These should be avoided per [[WP:TWODABS]]. Limited to 500 entries; Last updated <onlyinclude>~~~~~</onlyinclude>


{| class="wikitable sortable plainlinks"
|-
!Page
!Number of Links
%s
|}"""




print 'Getting list...'
query = """SELECT Distinct page_title, (select count(*) from pagelinks where pl_from=page_id and pl_namespace in (0,14,10)) as pl
from page
join templatelinks on tl_from = page_id and tl_namespace = 10 and tl_title = 'Disambiguation'
where page_namespace=0 having pl<=2 
Limit 500;
"""
db.query(query)
del query
for page,count in db.use_result().fetch_row(0):
	rows+=u'\n|-'
	rows+=u'\n| [[%s]]\n|%d'%(unicode(page,'utf-8').replace('_',' '),count)
rows+=u'\n|-'
template=template%rows
wikipedia.Page(wikipedia.getSite(),page_title).put(template,comment ='Updating list',botflag=False)

Crontab[edit]

0 5 8 * * python /home/tim1357/pynew/pywikipedia/smalldisambig.py