#configpage_title='%sTiny disambiguation pages'importsettingsimportwikipediaimportMySQLdbpage_title=page_title%settings.rootpagerows=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 plfrom pagejoin 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)delqueryforpage,countindb.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%rowswikipedia.Page(wikipedia.getSite(),page_title).put(template,comment='Updating list',botflag=False)