-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmost_linked_disambig_pages.py
executable file
·56 lines (48 loc) · 1.75 KB
/
most_linked_disambig_pages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import toolforge
import pywikibot as pw
import helpers
from helpers import matrix_to_wikitable
conn = toolforge.connect('hywiki')
hywiki = pw.Site('hy', 'wikipedia')
page = pw.Page(hywiki, 'Վիքիպեդիա:Ցանկեր/շատ հղվող բազմիմաստության փարատման էջեր')
sql = '''WITH DisambigPages AS
(SELECT DISTINCT p.page_title AS title
FROM page AS p
JOIN categorylinks cl ON p.page_id = cl.cl_from
WHERE cl.cl_to = 'Բազմիմաստության_փարատման_էջեր' AND p.page_namespace = 0 ),
DisambigRedirect AS
(SELECT DISTINCT p.page_title title
FROM redirect
JOIN page AS p ON rd_from = p.page_id
WHERE p.page_namespace = 0
AND rd_title IN
(SELECT title
FROM DisambigPages) ),
AllDisamig AS
(SELECT title
FROM DisambigPages
UNION SELECT title
FROM DisambigRedirect)
SELECT lt_title,
count(*) as C
FROM pagelinks
JOIN page AS p1 ON p1.page_id = pl_from
JOIN linktarget ON pl_target_id = lt_id
AND p1.page_is_redirect = 0
WHERE lt_title in (SELECT title FROM AllDisamig) AND p1.page_namespace = 0
GROUP BY lt_title
HAVING c > 1
ORDER BY C DESC, lt_title'''
with conn.cursor() as cur:
text = 'Տես նաև՝ [[Վիքիպեդիա:Ցանկեր/ամենաշատ բազմիմաստ հղում ունեցող հոդվածներ]]\n'
table = [['Հոդված', 'Քանակ']]
cur.execute(sql)
results = cur.fetchall()
for r in results:
title = helpers.get_cell_txt(r[0])
table.append([
f'[[{title}]] ([[Սպասարկող:Այստեղհղվողէջերը/{title}|հղումներ]])',
str(r[1])
])
page.text = text + matrix_to_wikitable(table)
page.save(summary='թարմացում', botflag=False)