#!/usr/bin/env python # -*- coding: utf-8 -*- import wikipedia import oursql import cgitb; cgitb.enable(logdir='tracebacks') connections = {} def getConn(wiki, host=""): if not wiki.endswith('_p'): wiki+='_p' if (host,wiki) not in connections: connections[host,wiki] = oursql.connect( db=wiki, host=host or wiki.replace('_', '-')+'.rrdb.toolserver.org', read_default_file="/home/dispenser/.my.cnf", charset=None, use_unicode=False ) return connections[host,wiki] def reconnect(wiki, host=""): if not wiki.endswith('_p'): wiki+='_p' del connections[host,wiki] return getConn(wiki, host) def main(): banners = [] min_results = 500 project_results = 0 def createLink(title, label): return '%s'%tuple(wikipedia.escape(s) for s in ("en.wikipedia.org", wikipedia.urllib.quote(title.replace(' ', '_')), title.replace('_', ' '), label or title.replace('_', ' '), )) for arg in wikipedia.handleArgs(): if arg.startswith('-banner:'): try: banners = arg[8:].decode('utf-8').encode('utf-8').split('|') except: banners = arg[8:].decode('latin-1').encode('utf-8').split('|') conn=getConn("enwiki_p", "sql-s1-user") cursor = conn.cursor() wikipedia.logtime('Database connection') print """
' wikipedia.logtime('Calculated update lag') for banner in banners: cursor.execute("""/* topic_points LIMIT:180 */ SELECT adl.article_title AS "Article", GROUP_CONCAT(adl.dab_title SEPARATOR "|") AS "Dab links", COUNT(c_id) AS "Points", IF(tl_from IS NULL, "", "Yes") AS "{{dn}}"/*, -- EXISTS (SELECT 1 FROM pagelinks WHERE pl_from=adl.article_id AND pl_namespace=0 AND pl_title=adl.dab_title) AS "Still linked?", (SELECT COUNT(*) FROM pagelinks JOIN page ON page_namespace=pl_namespace AND page_title=pl_title JOIN u_dispenser_p.projectbanner AS plb ON plb.pb_page=page_id AND plb.pb_title=? WHERE pl_from=adl.dab_id ) AS "ProjChoice" /*-*/ FROM u_dispenser_p.projectbanner JOIN p_dpl_p.all_dab_links_basic AS adl ON article_id=pb_page %s JOIN p_dpl_p.contest_dabs ON c_id=dab_id LEFT JOIN templatelinks ON tl_from=pb_page AND tl_namespace=10 AND tl_title="Disambiguation_needed" LEFT JOIN p_dpl_p.ch_fixed_links AS cfl ON cfl.article_id=adl.article_id AND cfl.dab_id=adl.dab_id WHERE pb_title=? AND cfl.article_id IS NULL GROUP BY pb_page ORDER BY FLOOR(LOG(5, COUNT(c_id))) DESC, Article ASC; """ % ("" if project_results > min_results else "LEFT",), (banner,)) wikipedia.logtime('Queried dablinks pages') print '| %s | '%tup[0] print '||||
|---|---|---|---|---|
| %s | %s | %d | %s | FIX |
Database operational error, retrying a few minutes.
%s'%(wikipedia.escape(strerror),) print '' else: raise finally: wikipedia.endContent() wikipedia.stopme()