User:QuasiBot/ioconjdata.py

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
# Conjdata module
 
from general import *
from string import *
 
site = getSite(language, family)
 
config.put_throttle = 1
put_throttle.setDelay()
 
list_verb = ['as', 'is', 'os', 'abis', 'abos', 'us', 'u', 'abus', 'ez', 'abez', 'ir', 'or']
list_adj = ['anta', 'inta', 'onta']
list_adj_pass = ['ata', 'ita', 'ota']
list_noun = ['anto', 'into', 'onto', 'anti', 'inti', 'onti']
list_noun_pass = ['ato', 'ito', 'oto', 'ati', 'iti', 'oti']
list_adv = ['ante', 'inte', 'onte']
list_adv_pass = ['ate', 'ite', 'ote']
 
list_active_only = list_verb + list_adj + list_noun + list_adv
list_active_and_passive = list_active_only + list_adj_pass + list_noun_pass + list_adv_pass
 
def upload(list, stem):
    mypage = 'User:QuasiBot/log'
    page = Page(site, mypage)
    text = page.get()
    newtext = text
    logmessage1 = u"<br>{{subst:User:QuasiBot/TimeStamp}}"
    logmessage2 = u": [ioconjdata] upload({0}, {1})"
    logmessage2 = logmessage2.format(list, stem, re.UNICODE)
    logmessage1 += logmessage2
    newtext += u"\n%s" % logmessage1
    showDiff(text, newtext)
    choice = inputChoice(u'Do you want to accept these changes?', ['Yes', 'No'], ['y', 'N'], 'N')
    if choice == 'n':
        return False
    # page.put(newtext, 'Bot: adding log entry.')
 
    preload = '{{subst:User:QuasiBot/io|' + stem + '|{0}}}'
    # autosummary = 'preloading ' + preload + ' with Python/pywikibot'
    autominor = True
    pageexists = []
    for ending in list:
        mypreload = '{' + preload.format(ending) + '}'
        mypage = stem + ending
        page = Page(site, mypage)
        try:
            pagetext = page.get()
            # pageexists.append(mypage)
            # print "Page", mypage, "already exists."
            # BEGIN iaconjdata SPLICE
            newpagetext = ''
            dont_edit = 0
            if find(pagetext, '==Ido==') > -1:
                print "Ido is already there!"
                pageexists.append(mypage)
                dont_edit = 1
            elif find(pagetext, '==Italian==') > -1:
                newpagetext = replace(pagetext, '==Italian==', '{{subst:User:QuasiBot/io|'+stem+'|'+ending+'}}\n\n----\n\n==Italian==')
            elif find(pagetext, '==Latin==') > -1:
                newpagetext = replace(pagetext, '==Latin==', '{{subst:User:QuasiBot/io|'+stem+'|'+ending+'}}\n\n----\n\n==Latin==')
            elif find(pagetext, '==Portuguese==') > -1:
                newpagetext = replace(pagetext, '==Portuguese==', '{{subst:User:QuasiBot/io|'+stem+'|'+ending+'}}\n\n----\n\n==Portuguese==')
            elif find(pagetext, '==Romanian==') > -1:
                newpagetext = replace(pagetext, '==Romanian==', '{{subst:User:QuasiBot/io|'+stem+'|'+ending+'}}\n\n----\n\n==Romanian==')
            elif find(pagetext, '==Spanish==') > -1:
                newpagetext = replace(pagetext, '==Spanish==', '{{subst:User:QuasiBot/io|'+stem+'|'+ending+'}}\n\n----\n\n==Spanish==')
            elif find(pagetext, '==Swedish==') > -1:
                newpagetext = replace(pagetext, '==Swedish==', '{{subst:User:QuasiBot/io|'+stem+'|'+ending+'}}\n\n----\n\n==Swedish==')
            else:
                print "WARNING: No under-language found!"
                # search for under-interwiki links here
                # ...
                # if interwiki links not found
                print "WARNING: No under-interwiki links found!"
                newpagetext = pagetext + '\n\n----\n\n{{subst:User:QuasiBot/io|'+stem+'|'+ending+'}}'
            if (dont_edit == 0):
                print('\n\nNEWPAGETEXT:\n')
                print(newpagetext)
                wikipedia.showDiff(pagetext, newpagetext)
                choice = wikipedia.inputChoice(' OK?', ['Yes', 'No'], ['y', 'n'], 'n')
                if ((newpagetext != pagetext) and (choice == 'y')):
                    myautosummary = 'stamping ' + mypreload + ' with Python/pywikibot'
                    page.put(newpagetext, comment=myautosummary, minorEdit=autominor)
                else:
                    pageexists.append(mypage)
                    print "Page", mypage, "already exists."
            # END iaconjdata SPLICE
        except NoPage:
            myautosummary = 'preloading ' + mypreload + ' with Python/pywikibot'
            page.put(mypreload, comment=myautosummary, minorEdit=autominor)
    mypage = 'User:QuasiBot/log'
    page = Page(site, mypage)
    text = page.get()
    newtext = text
    logmessage = ": " + str(pageexists)
    newtext += u"\n%s" % logmessage
    showDiff(text, newtext)
    choice = inputChoice(u'Do you want to accept these changes?', ['Yes', 'No'], ['y', 'N'], 'N')
    if choice == 'N':
        return False
    # page.put(newtext, 'Bot: adding log entry.') 
    return pageexists