ويكيبيديا:تقارير قاعدة البيانات/Unused templates/Configurationunusedtemplates.py#! /usr/bin/env python
# Public domain; bjweeks, MZMcBride; 2011
import datetime
import math
import MySQLdb
import wikitools
import settings
report_title = settings.rootpage + 'Unused templates/%i'
report_template = u'''\
Unused templates; data as of <onlyinclude>%s</onlyinclude>.
{| class="wikitable sortable plainlinks" style="width:100%%; margin:auto;"
|- style="white-space:nowrap;"
! No.
! Template
|-
%s
|}
'''
rows_per_page = 1000
wiki = wikitools.Wiki(settings.apiurl)
wiki.login(settings.username, settings.password)
def get_substituted_templates(cursor):
templates = []
cursor.execute('''
/* unusedtemplates.py */
SELECT
page_title
FROM page
JOIN categorylinks
ON page_id = cl_from
WHERE cl_to = 'Wikipedia_substituted_templates'
AND page_namespace = 10;
''')
for row in cursor.fetchall():
page_title = unicode(row[0], 'utf-8')
templates.append(page_title)
return templates
conn = MySQLdb.connect(host=settings.host,
db=settings.dbname,
read_default_file='~/.my.cnf')
cursor = conn.cursor()
substituted_templates = get_substituted_templates(cursor)
cursor.execute('''
/* unusedtemplates.py SLOW_OK */
SELECT
ns_name,
page_title
FROM page
JOIN toolserver.namespace
ON dbname = %s
AND page_namespace = ns_id
LEFT JOIN redirect
ON rd_from = page_id
LEFT JOIN templatelinks
ON page_namespace = tl_namespace
AND page_title = tl_title
WHERE page_namespace = 10
AND rd_from IS NULL
AND tl_from IS NULL;
''' , settings.dbname)
i = 1
output = []
for row in cursor.fetchall():
ns_name = u'%s' % unicode(row[0], 'utf-8')
page_title = u'%s' % unicode(row[1], 'utf-8')
full_page_title = u'[[%s:%s|%s]]' % (ns_name, page_title, page_title)
table_row = u'''\
| %d
| %s
|-''' % (i, full_page_title)
if (not page_title.endswith('/doc') and
not page_title.endswith('/testcases') and
not page_title.endswith('/sandbox') and
not page_title.startswith('Editnotices/') and
not page_title.startswith('Cite_doi/') and
not page_title.startswith('Cite_pmid/') and
not page_title.startswith('TFA_title/') and
not page_title.startswith('POTD_protected/') and
not page_title.startswith('POTD_credit/') and
not page_title.startswith('POTD_caption/') and
not page_title.startswith('Did_you_know_nominations/') and
not page_title.startswith('Child_taxa//') and
page_title not in substituted_templates):
output.append(table_row)
i += 1
cursor.execute('''
SELECT
UNIX_TIMESTAMP() - UNIX_TIMESTAMP(rc_timestamp)
FROM recentchanges
ORDER BY rc_timestamp DESC
LIMIT 1;
''')
rep_lag = cursor.fetchone()[0]
time_diff = datetime.datetime.utcnow() - datetime.timedelta(seconds=rep_lag)
current_of = time_diff.strftime('%H:%M, %d %B %Y (UTC)')
end = rows_per_page
page = 1
for start in range(0, len(output), rows_per_page):
report = wikitools.Page(wiki, report_title % page)
report_text = report_template % (current_of, '\n'.join(output[start:end]))
report_text = report_text.encode('utf-8')
report.edit(report_text, summary=settings.editsumm, bot=1)
page += 1
end += rows_per_page
page = math.ceil(len(output) / float(rows_per_page)) + 1
while 1:
report = wikitools.Page(wiki, report_title % page)
report_text = settings.blankcontent
report_text = report_text.encode('utf-8')
if not report.exists:
break
report.edit(report_text, summary=settings.blanksumm, bot=1)
page += 1
cursor.close()
conn.close()
crontab0 15 * * 4 python ~/scripts/database-reports/unusedtemplates.py > /dev/null
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia