User:QuasiBot/iaconjdata.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_ar = ['a', 'ava', 'ara', 'area', 'ante', 'ate'];
list_er = ['e', 'eva', 'era', 'erea', 'ente', 'ite(er)'];
list_ir = ['i', 'iva', 'ira', 'irea', 'iente', 'ite(ir)'];
 
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": [iaconjdata] 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:ia-verb-entry-form|' + stem + '|{0}}}'
    insertiontext = '{{subst:ia-verb-entry-form|' + stem + '|{0}}}'
    # autosummary = 'preloading ' + preload + ' with Python/pywikibot'
    autominor = True
    pageexists = []
    for ending in list:
        mypreload = '{' + preload.format(ending) + '}'
        myinsertiontext = '{' + insertiontext.format(ending) + '}'
        title_ending = ending
        if ending[:3] == 'ite':
            title_ending = 'ite'
        mypage = stem + title_ending
        page = Page(site, mypage)
        try:
            print('Page title is: '+mypage)
            pagetext = page.get()
            print('--------------')
            print('\nPage content is:\n\n'+pagetext)
            # pageexists.append(mypage)
            newpagetext = ''
            overlang = ''
            # search for over-language
            if find(pagetext, '==Corsican==') > -1:
                overlang = '\n'
            cond = (mypage[-1:] == 'a' and title_ending == 'a') or (mypage[-3:] == 'ava') or (mypage[-3:] == 'ara')
            cond = cond or (mypage[-4:] == 'ante') or (mypage[-3:] == 'ate') or (mypage[-1:] == 'e' and title_ending == 'e')
            cond = cond or (mypage[-3:] == 'eva') or (mypage[-3:] == 'era') or (mypage[-4:] == 'ente')
            cond = cond or (mypage[-3:] == 'ite') or (mypage[-1:] == 'i') or (mypage[-3:] == 'iva')
            cond = cond or (mypage[-3:] == 'ira') or (mypage[-5:] == 'iente')
            dont_edit = 0
            if (cond):
                if find(pagetext, '==Interlingua==') > -1:
                    print "There is an Interlingua entry already!"
                    dont_edit = 1
                    pageexists.append(mypage)
                elif find(pagetext, '==Italian==') > -1:
                    newpagetext = replace(pagetext, '==Italian==', overlang+'{{subst:ia-verb-entry-form|'+stem+'|'+ending+'}}\n\n----\n\n==Italian==')
                elif find(pagetext, '==Latin==') > -1:
                    newpagetext = replace(pagetext, '==Latin==', overlang+'{{subst:ia-verb-entry-form|'+stem+'|'+ending+'}}\n\n----\n\n==Latin==')
                elif find(pagetext, '==Romanian==') > -1:
                    newpagetext = replace(pagetext, '==Romanian==', overlang+'{{subst:ia-verb-entry-form|'+stem+'|'+ending+'}}\n\n----\n\n==Romanian==')
                elif find(pagetext, '==Spanish==') > -1:
                    newpagetext = replace(pagetext, '==Spanish==', overlang+'{{subst:ia-verb-entry-form|'+stem+'|'+ending+'}}\n\n----\n\n==Spanish==')
                elif find(pagetext, '==Swedish==') > -1:
                    newpagetext = replace(pagetext, '==Swedish==', overlang+'{{subst:ia-verb-entry-form|'+stem+'|'+ending+'}}\n\n----\n\n==Swedish==')
                elif find(pagetext, '==Portuguese==') > -1:
                    newpagetext = replace(pagetext, '==Portuguese==', overlang+'{{subst:ia-verb-entry-form|'+stem+'|'+ending+'}}\n\n----\n\n==Portuguese==')
                else:
                    print "WARNING: No under-language found!"
                    # search for under-interwiki links here
                    if find(pagetext, '[[ru:') > -1:
                        newpagetext = replace(pagetext, '[[ru:', '----\n\n{{subst:ia-verb-entry-form|'+stem+'|'+ending+'}}\n\n[[ru:')
                    else: 
                        # if interwiki links not found
                        print "WARNING: No under-interwiki links found!"
                        newpagetext = pagetext + '\n\n----\n\n{{subst:ia-verb-entry-form|'+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 ' + myinsertiontext + ' with Python/pywikibot'
                    page.put(newpagetext, comment=myautosummary, minorEdit=autominor)
                else:
                    pageexists.append(mypage)
                    print "Page", mypage, "already exists."
        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

Comments[edit]

  • The repetition could be abstracted out (as has been done with eoconjdata.py).
  • Is the overlang part necessary? (It doesn't seem to be.)