JAnD added a comment.

@JAnD I remember you worked with main cats once, maybe you would share the code

I found the script, but the author of code was @Ladsgroup

#!/usr/bin/python
#coding: utf-8
import wikipedia, codecs, re
site = wikipedia.getSite("cs")
f = codecs.open("cswiki.txt","r","utf-8")
rer = re.compile("\[\[(.+?)\]\]")
aaa = rer.findall(f.read())
f.close()
excludes = [u'{{Rozcestník',u'{{rozcestník',u'{{Přesměrování']
for name in aaa:
    page = wikipedia.Page(site,name)
    try:
        text = page.get()
    except:
        continue
    ok = True
    for exclude in excludes:
        if exclude in text:
            ok = False
    if not ok:
        continue
    new_text = re.sub(u"\[\[Kategorie\:%s(\|.*?)? *?]]" % re.escape(page.title()),"",text)
    add_text = u"[[Kategorie:%s| ]]" % page.title()
    if u"\n[[Kategorie" in new_text:
        new_text = new_text.replace(u"\n[[Kategorie",add_text+u"\n[[Kategorie",1)
    else:
        new_text += add_text
    if new_text!= text:
        page.put(new_text, u"Hlavní kategorie: jako první, řadicí klíč")

TASK DETAIL
https://phabricator.wikimedia.org/T76298

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: JAnD
Cc: Dvorapa, JAnD, jayvdb, pywikibot-bugs-list, Ladsgroup, Magul, Tbscho, rafidaslam, MayS, Mdupont, JJMC89, Avicennasis, Dalba, Masti, Alchimista, Rxy
_______________________________________________
pywikibot-bugs mailing list
pywikibot-bugs@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to