-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserpage_cats.py
More file actions
executable file
·48 lines (42 loc) · 2.19 KB
/
userpage_cats.py
File metadata and controls
executable file
·48 lines (42 loc) · 2.19 KB
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
import toolforge, re, time
import pywikibot as pw
import helpers
from helpers import matrix_to_wikitable
hywiki = pw.Site('hy', 'wikipedia')
query = '''SELECT DISTINCT page_title, cl_to
FROM categorylinks JOIN page ON page_id = cl_from
WHERE page_namespace = 2
AND cl_to NOT IN (SELECT page_title
FROM page JOIN page_props ON page_id = pp_page
WHERE pp_propname = 'hiddencat')
AND cl_to IN (SELECT cl_to
FROM categorylinks JOIN page ON page_id = cl_from
WHERE page_namespace = 0);'''
conn = toolforge.connect('hywiki')
skip = {}
skipPage = pw.Page(hywiki, 'Վիքիպեդիա:Ցանկեր/հոդվածների հետ նույն կատեգորիայում ապրող մասնակցային էջեր/անտեսել')
if skipPage.exists():
skipPages = skipPage.text.splitlines()
for line in skipPages:
line = re.sub(r'^\* *(.+) *\n?', r'\1', line)
line = line.replace('Մասնակից:', '')
skip[line] = True
with conn.cursor() as cur:
cur.execute(query)
results = cur.fetchall()
text = [['Մասնակցային էջ', 'Կատեգորիա']]
for r in results:
try:
if helpers.get_cell_txt(r[0]) not in skip:
thispage = pw.Page(hywiki, 'Մասնակից:' + helpers.get_cell_txt(r[0]))
thispage.text = re.sub(r'\[\[([Կկ]ատեգորիա|[Cc]ategory):', '[[:Կատեգորիա:', thispage.text)
thispage.save(summary='Կատեգորիան հեռացնում եմ ավազարկղից')
time.sleep(30)
if list(filter(lambda x: not x.isHiddenCategory(), list(thispage.categories()))):
text.append(
['[[Մասնակից:' + helpers.get_cell_txt(r[0]) + ']]', '[[:Կատեգորիա:' + helpers.get_cell_txt(r[1]) + ']]'])
except:
continue
p = pw.Page(hywiki, 'Վիքիպեդիա:Ցանկեր/հոդվածների հետ նույն կատեգորիայում ապրող մասնակցային էջեր')
p.text = matrix_to_wikitable(text)
p.save(summary='թարմացում', botflag=False)