-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_red_links.py
47 lines (41 loc) · 1.76 KB
/
math_red_links.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
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 AllMainTitle AS
(SELECT page_title AS title
FROM page
WHERE page_namespace = 0),
AllMathTitles AS
(SELECT DISTINCT page_title AS math_page_title
FROM templatelinks
JOIN linktarget ON lt_id = tl_target_id
JOIN page ON page_id = tl_from
WHERE lt_title = "Վիքինախագիծ_Մաթեմատիկա")
SELECT pl_title,
count(*) c
FROM pagelinks
JOIN page ON page_id = pl_from
WHERE pl_namespace = 0
AND page_namespace = 0
AND pl_title not in
(SELECT title
FROM AllMainTitle)
AND page_title in
(SELECT math_page_title
FROM AllMathTitles)
GROUP BY pl_title
HAVING c > 4
ORDER BY c DESC'''
with conn.cursor() as cur:
table = [['Հղումներ', 'Հոդված']]
cur.execute(sql)
page.text = 'Ստորև ներկայացված են մաթեմատիկային վերաբերող հոդվածներում պահանջված հոդվածները։ Հնարավոր է, որ հոդվածների մի մասը արդեն գոյություն ունի այլ անունով, այդ դեպքում հարկավոր է վերահղում տալ։ Ցուցակը տեսակավորված է ըստ հոդվածների պահանջարկի (կարմիր հղումների քանակի)։\n'
results = cur.fetchall()
for r in results:
table.append([r[1], f"[[{helpers.get_cell_txt(r[0])}]]"])
page.text = matrix_to_wikitable(table)
page.save(summary='թարմացում', botflag=False)