-
Notifications
You must be signed in to change notification settings - Fork 0
/
createredirects.py
47 lines (35 loc) · 1 KB
/
createredirects.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 pywikibot, os
from multiprocessing.dummy import Pool as ThreadPool
#os.chdir(r'projects/redirect')
REDIRECT = '#REDIRECT [[{}]]'
site = pywikibot.Site("lv", "wikipedia")
pairs= []
files = [
#'lvwiki-visicilveki-redirects-tocrete.txt',
'lvwiki-visicilveki-redirects-tocrete-2222.txt',
'lvwiki-visicilveki-redirects-tocrete2.txt',
'lvwiki-visicilveki-redirects-enwiki-uzv.txt'
]
for file in files:
curfile = eval(open(file,'r', encoding='utf-8').read())
pairs.extend(curfile)
print(len(pairs))
def one_r(id):
redirectpage,target = id
redpage = pywikibot.Page(site,redirectpage)
if redpage.exists():
return
target = target[0]
#redpage.put(REDIRECT.format(target), 'Pāradresē uz [[%s]]' % target)
redpage.text = REDIRECT.format(target)
redpage.save(summary='Pāradresē uz [[%s]]' % target, as_group='sysop')
#
pooling = False
if pooling:
pool = ThreadPool(8)
pool.map(one_r,pairs)
pool.close()
pool.join()
else:
for one in pairs:
one_r(one)