This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathczescimowyReplace.py
70 lines (63 loc) · 2.33 KB
/
czescimowyReplace.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pywikibot
from pywikibot import Category
from pywikibot import pagegenerators
import re
from pywikibot import xmlreader
import collections
from klasa import *
import config
#uwagi wstępne
#nie można zmieniać ''przymiotnik -> ''przymiotnik'', bo będą niepożądane zmiany, ewentualnie można byłoby szukać ''przymiotnik\n i zmieniać, ale struktura hasła w parserze jest taka, że to \n nie wchodzi do zmiennej
def czescimowyReplace():
site = pywikibot.Site()
inp = codecs.open('%soutput/czescimowy_input.txt' % config.path['scripts'], encoding='utf-8')
replacePage = pywikibot.Page(site, 'Wikipedysta:AlkamidBot/części_mowy/zamiana')
replacePageText = replacePage.get()
tempListReplace = replacePageText.split('\n')
replaceList = []
cnt = 0
for elem in tempListReplace:
if elem == '|-':
old = ''
new = ''
cnt = 1
if cnt == 1:
cnt += 1
elif cnt == 2:
old = elem[1:]
cnt += 1
elif cnt == 3:
new = elem[1:]
replaceList.append([old, new])
cnt = 1
#for replaceText in replaceList:
# print replaceText[0]
# print replaceText[1]
for line in inp:
if line:
try: h = Haslo(line)
except sectionsNotFound:
pass
except pywikibot.InvalidTitle:
pass
except AttributeError:
pass
else:
#print h.title
if h.type == 3:
changed = 0
for c in h.listLangs:
c.pola()
if c.type == 1:
for d in c.znaczeniaDetail:
temp = d[0]
for replaceText in replaceList:
d[0] = d[0].replace(replaceText[0], replaceText[1])
if d[0] != temp:
c.saveChanges()
if d[0] != temp:
changed = 1
if changed:
h.push(myComment='automatyczne porządkowanie części mowy wg [[Wikipedysta:AlkamidBot/części_mowy/zamiana]]')