Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
- import pywikibot
- import time
- def joReplacer(word, startIndex = 0, replaced=False):
- result = []
- count = word.count(u'ё', startIndex)
- if count > 1 or (count == 1 and replaced):
- newStartIndex = word.find(u'ё', startIndex) + 1
- result.extend(joReplacer(word, newStartIndex, replaced))
- result.extend(joReplacer(word[:startIndex] + word[startIndex:].replace(u'ё', u'е', 1), newStartIndex, True))
- elif count == 1:
- result.append(word[:startIndex] + word[startIndex:].replace(u'ё', u'е'))
- else:
- result.append(word)
- return result
- def processLine(line):
- masterWord = unicode(line[:-1], 'utf8')
- masterPage = pywikibot.Page(site, masterWord)
- if site.page_isredirect(masterPage):
- masterPage = masterPage.getRedirectTarget()
- for word in joReplacer(masterWord):
- page = pywikibot.Page(site, word)
- if (page.text == ''):
- page.text = u"#REDIRECT [[" + masterPage.title() + u"]]"
- #page.set_redirect_target(masterPage, create=True)
- site.editpage(page, u'Тестовая проверка ё-перенаправлятора')
- filename = "no_jo.txt"
- site = pywikibot.Site()
- site.login()
- lines = open(filename).readlines()
- for i, line in enumerate(lines[:]):
- processLine(line)
- del lines[0]
- time.sleep(10)
- open(filename, "w").writelines(lines)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement