위키백과:데이터베이스 보고서/문서가 포함된 틀 분류/구성

# -*- coding: utf-8 -*-

import pymysql as pms
import pywikibot as pwb
from datetime import datetime
from zoneinfo import ZoneInfo
import locale

def asof():
    locale.setlocale(locale.LC_TIME, "ko_KR.UTF-8")
    KST = ZoneInfo("Asia/Seoul")
    return datetime.now(KST).strftime('%Y년 %-m월 %-d일 (%a) %H:%M (KST)')

site = pwb.Site()
page = pwb.Page(site, "위키백과:데이터베이스 보고서/문서가 포함된 틀 분류")
text = f'''틀이나 분류가 아닌 문서가 포함된 틀 분류를 정리한 보고서입니다.

마지막 갱신: <onlyinclude>{asof()}</onlyinclude>

{{| class="wikitable sortable plainlinks" style="width: 100%; margin: auto;"
|- style="white-space: nowrap;"
! 순번
! 분류 이름
'''

conn = pms.connect(host='kowiki.analytics.db.svc.wikimedia.cloud', user='#####', password='#####', db='kowiki_p')
cursor = conn.cursor()
cursor.execute('''SELECT
  page_title
FROM
  page AS pg1
  JOIN categorylinks AS cl1 ON pg1.page_id = cl1.cl_from
WHERE
  pg1.page_namespace = 14
  AND cl1.cl_to = '위키백과_틀_분류'
  AND EXISTS (
    SELECT
      1
    FROM
      page AS pg2
      JOIN categorylinks AS cl2 ON pg2.page_id = cl2.cl_from
    WHERE
      pg2.page_namespace != 10
      AND pg2.page_namespace != 14
      AND pg1.page_title = cl2.cl_to
  )
ORDER BY
  page_title;''')

kowiki_ns = {-2: '미디어', -1: '특', 1: '토론', 2: '사', 3: '사토', 4: '백', 5: '백토', 6: '파일', 7: '파일토론', 8: '미디어위키', 9: '미디어위키토론', 10: '틀', 11: '틀토론', 12: '도움말', 13: '도움말토론', 14: '분류', 15: '분류토론', 100: '들', 101: '들토', 102: '프', 103: '프토', 118: '초안', 119: '초안토론', 828: '모듈', 829: '모듈토론', 710: 'TimedText', 711: 'TimedText talk'}
for i, row in enumerate(cursor.fetchall(), start=1):
    table_row = (
        f'|-\n'
        f'| {i}\n'
        f"| [[:분류:{row[0].decode('utf-8').replace('_', ' ')}]]\n"
    )
    text += table_row

text += '|}\n\n'

print(text)
page.text = text
page.save("database report")
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia

Kembali kehalaman sebelumnya