Open main menu

Wikidata:Database reports/List of properties/Top100/Configuration

# -*- coding: UTF-8 -*-
#licensed under CC-Zero:

import MySQLdb
import pywikibot
import time

site = pywikibot.Site('wikidata','wikidata')

header = 'A list of the top 100 [[Wikidata:Properties|properties]] by quantity of item pages that link to them. Data as of <onlyinclude>{0}</onlyinclude>.\n\n{{| class="wikitable sortable" style="width:100%; margin:auto;"\n|-\n! {{{{i18n|property}}}} !! Usage\n'

table_row = '|-\n| {{{{P|{0}}}}} || {1}\n'

footer = '|}\n\n[[Category:Properties]]\n[[Category:Wikidata statistics]]'

query1 = 'SELECT pl_title, count(*) AS cnt FROM pagelinks WHERE pl_from_namespace=0 AND pl_namespace=120 GROUP BY pl_title ORDER BY cnt DESC limit 0,100'

def makeReport(db):
	cursor = db.cursor()
	text = ''
	for property, cnt in cursor:
		text += table_row.format(property,cnt)
	return text

def main():
	page = pywikibot.Page(site,'Wikidata:Database reports/Popular properties')
	db = MySQLdb.connect(host="wikidatawiki.labsdb",db="wikidatawiki_p", read_default_file="~/")
	report = makeReport(db)
	text = header.format(time.strftime("%H:%M, %d %B %Y (%Z)")) + report + footer
	page.put(text.decode('UTF-8'),comment='Bot:Updating database report',minorEdit=False)

if __name__ == "__main__":