From a062b6426d8374016b37f72572d6baa630e82b09 Mon Sep 17 00:00:00 2001 From: notconfusing Date: Tue, 21 Aug 2012 13:14:47 -0700 Subject: [PATCH] batched log writing --- viafbot.py | 306 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 181 insertions(+), 125 deletions(-) diff --git a/viafbot.py b/viafbot.py index 1068514..e106906 100644 --- a/viafbot.py +++ b/viafbot.py @@ -3,21 +3,35 @@ # CC-BY-SA Max Klein and OCLC Research # importing modules # requires that pywikipediabot modules be in your PYTHONPATH -import sys import wikipedia import exceptions import textlib -from add_text_customised import * #for method writeEntireTemplate -from replace_customised import * #for method writeVIAFaramOnly +import add_text_customised#for method writeEntireTemplate +#if using writeVIAFparamOnly not writeVIAFparamOnly2: from time import gmtime, strftime #for timestamping -# variables +#wikipedia site variables enwp = wikipedia.getSite('en','wikipedia') dewp = wikipedia.getSite('de','wikipedia') +#files wikilinksfile = open("userspacetest.out")#should be wikilinksforbot.out when real wikilinks = wikilinksfile.readlines() viafbotrun = open("viafbotrun.log", 'w+') +NoDEWPlog = open("NoDEWP.log", 'w+') +YesDEWPlog = open("YesDEWP.log", 'w+') +conflict4log = open("conflict4.log", 'w+') +conflict6log = open("conflict6.log", 'w+') +conflict8log = open("conflict8.log", 'w+') +conflict11log = open("conflict11.log", 'w+') +conflict12log = open("conflict12.log", 'w+') +conflict13log = open("conflict13.log", 'w+') +superfluouslog = open("superfluous.log", 'w+') +lockedErrorlog = open("lockedError.log", 'w+') +editConflictErrorlog = open("editConflictError.log", 'w+') +pageNotSavedErrorlog = open("pageNotSavedError.log", 'w+') +spamfilterErrorlog = open("spamfilterError.log", 'w+') +longPageErrorlog = open("longPageError.log", 'w+') #global stats touched = 0 totalRedirects = 0 @@ -166,7 +180,7 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts writeEntireTemplate(validatedPage, viafnum) logOnWiki(1,validatedPage, viafnum) elif acStatus == 'templateNoVIAF': - writeVIAFparamOnly(validatedPage,viafnum) + writeVIAFparamOnly2(validatedPage,viafnum) logOnWiki(2, validatedPage, viafnum) elif type(acStatus)==int: if acStatus == viafnum: @@ -182,7 +196,7 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts logOnWiki(6, validatedPage, viafnum) elif acStatus == 'templateNoVIAF': if normdatenStatus == viafnum: #so there is a english template and viafnum agrees with dewp - writeVIAFparamOnly(validatedPage,viafnum) + writeVIAFparamOnly2(validatedPage,viafnum) logOnWiki(7, validatedPage, viafnum) else: logOnWiki(8, validatedPage, viafnum) @@ -200,7 +214,8 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts else: logOnWiki(13, validatedPage, viafnum) else: - raise exceptions.Error + raise exceptions.Error + #exceptions raised while trying to write except exceptions.LockedPage: if writeAttempts == 0: lockedError = lockedError + 1 @@ -209,7 +224,11 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts if writeAttempts <= 6: writeToWiki(validatedPage, acStatus, normdatenStatus, writeAttempts) else: - wikipedia.Page(enwp,'User:VIAFbot/Errors/Locked').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was locked ' , comment='Logging', minorEdit=True, section=0) + lockedErrorlog.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' was locked.\n' ) + if lockedError % 100 == 99: + wikipedia.Page(enwp,'User:VIAFbot/Errors/Locked').append(last100LogLinesAsString(lockedErrorlog), comment='Logging', minorEdit=True, section=0) + else: pass + except exceptions.PageNotSaved: if writeAttempts == 0: pageNotSavedError = pageNotSavedError + 1 @@ -218,7 +237,11 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts if writeAttempts <= 6: writeToWiki(validatedPage, acStatus, normdatenStatus, writeAttempts) else: - wikipedia.Page(enwp,'User:VIAFbot/Errors/PageNotSaved').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' generic page not saved' , comment='Logging', minorEdit=True, section=0) + pageNotSavedErrorlog.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' generic page not saved.\n' ) + if pageNotSavedError % 100 == 99: + wikipedia.Page(enwp,'User:VIAFbot/Errors/PageNotSaved').append(last100LogLinesAsString(pageNotSavedErrorlog), comment='Logging', minorEdit=True, section=0) + else: pass + except exceptions.EditConflict: if writeAttempts == 0: editConflictError = editConflictError + 1 @@ -227,7 +250,11 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts if writeAttempts <= 6: writeToWiki(validatedPage, acStatus, normdatenStatus, writeAttempts) else: - wikipedia.Page(enwp,'User:VIAFbot/Errors/EditConflict').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' edit conflict ' , comment='Logging', minorEdit=True, section=0) + editConflictErrorlog.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' editconflict.\n') + if editConflictError % 100 == 99: + wikipedia.Page(enwp,'User:VIAFbot/Errors/EditConflict').append(last100LogLinesAsString(editConflictErrorlog), comment='Logging', minorEdit=True, section=0) + else: pass + except exceptions.SpamfilterError: if writeAttempts == 0: spamfilterError = spamfilterError + 1 @@ -236,7 +263,11 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts if writeAttempts <= 6: writeToWiki(validatedPage, acStatus, normdatenStatus, writeAttempts) else: - wikipedia.Page(enwp,'User:VIAFbot/Errors/Spamfilter').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' did not pass spamfilter ' , comment='Logging', minorEdit=True, section=0) + spamfilterErrorlog.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' did not pass spamfilter.\n') + if spamfilterError % 100 == 99: + wikipedia.Page(enwp,'User:VIAFbot/Errors/Spamfilter').append(last100LogLinesAsString(spamfilterErrorlog), comment='Logging', minorEdit=True, section=0) + else: pass + except exceptions.LongPageError: if writeAttempts == 0: longPageError = longPageError + 1 @@ -245,9 +276,11 @@ def writeToWiki(validatedPage, acStatus, normdatenStatus, viafnum, writeAttempts if writeAttempts <= 6: writeToWiki(validatedPage, acStatus, normdatenStatus, writeAttempts) else: - wikipedia.Page(enwp,'User:VIAFbot/Errors/LongPage').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' page too long error ' , comment='Logging', minorEdit=True, section=0) + longPageErrorlog.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' page too long error.\n') + if longPageError % 100 == 99: + wikipedia.Page(enwp,'User:VIAFbot/Errors/LongPage').append(last100LogLinesAsString(longPageErrorlog), comment='Logging', minorEdit=True, section=0) + else: pass - def logOnWiki(casenum, validatedPage, viafnum): """ @@ -269,168 +302,175 @@ def logOnWiki(casenum, validatedPage, viafnum): """1 - |(nd)|, (ac) VIAF parameter written.""" if casenum == 1: - archiveNum = NoDEWP / 100 - wikipedia.Page(enwp,'User:VIAFbot/NoDEWP/' + str(archiveNum)).append('\n\n' + timestamp + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - NoDEWP = NoDEWP + 1 + NoDEWP += 1 + NoDEWPlog.write('* ' + timestamp + " . " + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum)+ '\n') + if NoDEWP % 100 == 99: + archiveNum = NoDEWP / 100 + wikipedia.Page(enwp,'User:VIAFbot/NoDEWP/' + str(archiveNum)).append( last100LogLinesAsString(NoDEWPlog) , comment='Logging', minorEdit=True, section=0) + else: pass """2 - |(nd)|, |ac| VIAF parameter written.""" if casenum == 2: - archiveNum = NoDEWP / 100 - wikipedia.Page(enwp,'User:VIAFbot/NoDEWP/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - NoDEWP = NoDEWP + 1 + NoDEWP += 1 + NoDEWPlog.write('* ' + timestamp + " . " + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum)+ '\n') + if NoDEWP % 100 == 99: + archiveNum = NoDEWP / 100 + wikipedia.Page(enwp,'User:VIAFbot/NoDEWP/' + str(archiveNum)).append( last100LogLinesAsString(NoDEWPlog) , comment='Logging', minorEdit=True, section=0) + else: pass """3 - |(nd)|, ac == vl No writing necessary.""" if casenum == 3: - archiveNum = superfluous / 100 - wikipedia.Page(enwp,'User:VIAFbot/Superfluous/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' ' + str(viafnum) + ' was already added to both enwp and dewp.', comment='Logging', minorEdit=True, section=0) - superfluous = superfluous + 1 + superfluous += 1 + superfluouslog.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' ' + str(viafnum) + ' was already added to both enwp and dewp.\n') + if superfluous % 100 == 99: + archiveNum = superfluous / 100 + wikipedia.Page(enwp,'User:VIAFbot/Superfluous/' + str(archiveNum)).append( last100LogLinesAsString(superfluouslog), comment='Logging', minorEdit=True, section=0) + else: pass """4 - |(nd)|, ac != vl requires human attention. Nothing written.""" if casenum == 4: - archiveNum = conflict4 / 100 - wikipedia.Page(enwp,'User:VIAFbot/Conflict/4/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' requires human attention: ac != vl . VIAF number: ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - conflict4 = conflict4 + 1 + conflict4 += 1 + conflict4log.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' requires human attention: ac != vl . VIAF number: ' + str(viafnum)) + if conflict4 % 100 == 99: + archiveNum = conflict4 / 100 + wikipedia.Page(enwp,'User:VIAFbot/Conflict/4/' + str(archiveNum)).append(last100LogLinesAsString(conflict4log), comment='Logging', minorEdit=True, section=0) + else: pass """5 - nd , (ac), nd == vl. VIAF parameter written.""" if casenum == 5: - archiveNum = YesDEWP / 100 - wikipedia.Page(enwp,'User:VIAFbot/YesDEWP/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - YesDEWP = YesDEWP + 1 + YesDEWP += 1 + YesDEWPlog.write('* ' + timestamp + " . " + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum)+ '\n') + if YesDEWP % 100 == 99: + archiveNum = YesDEWP / 100 + wikipedia.Page(enwp,'User:VIAFbot/YesDEWP/' + str(archiveNum)).append( last100LogLinesAsString(YesDEWPlog) , comment='Logging', minorEdit=True, section=0) + else: pass """6 - nd, (ac), nd != vl. requires human attention. Nothing Written.""" if casenum == 6: - archiveNum = conflict6 / 100 - wikipedia.Page(enwp,'User:VIAFbot/Conflict/6/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' requires human attention: nd != vl . VIAF number: ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - conflict6 = conflict6 + 1 + conflict6 += 1 + conflict6log.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' requires human attention: nd != vl . VIAF number: ' + str(viafnum)) + if conflict6 % 100 == 99: + archiveNum = conflict6 / 100 + wikipedia.Page(enwp,'User:VIAFbot/Conflict/6/' + str(archiveNum)).append(last100LogLinesAsString(conflict6log), comment='Logging', minorEdit=True, section=0) + else: pass """7 - nd, |ac|, nd == vl. VIAF parameter written.""" if casenum == 7: - archiveNum = YesDEWP / 100 - wikipedia.Page(enwp,'User:VIAFbot/YesDEWP/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - YesDEWP = YesDEWP + 1 + YesDEWP += 1 + YesDEWPlog.write('* ' + timestamp + " . " + validatedPage.title(asLink=True) + ' added VIAF number ' + str(viafnum)+ '\n') + if YesDEWP % 100 == 99: + archiveNum = YesDEWP / 100 + wikipedia.Page(enwp,'User:VIAFbot/YesDEWP/' + str(archiveNum)).append( last100LogLinesAsString(YesDEWPlog) , comment='Logging', minorEdit=True, section=0) + else: pass """8 - nd, |ac|, nd != vl. requires human attention.""" if casenum == 8: - archiveNum = conflict8 / 100 - wikipedia.Page(enwp,'User:VIAFbot/Conflict/8/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' requires human attention: nd != vl . VIAF number: ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - conflict8 = conflict8 + 1 + conflict8 += 1 + conflict8log.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' requires human attention: nd != vl . VIAF number: ' + str(viafnum)) + if conflict8 % 100 == 99: + archiveNum = conflict8 / 100 + wikipedia.Page(enwp,'User:VIAFbot/Conflict/8/' + str(archiveNum)).append(last100LogLinesAsString(conflict8log), comment='Logging', minorEdit=True, section=0) + else: pass """9 - nd, ac , nd == ac == vl. No writing necessary.""" if casenum == 9: - archiveNum = superfluous / 100 - wikipedia.Page(enwp,'User:VIAFbot/Superfluous/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + str(viafnum) + ' was already added to both enwp and dewp.', comment='Logging', minorEdit=True, section=0) - superfluous = superfluous + 1 + superfluous += 1 + superfluouslog.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' ' + str(viafnum) + ' was already added to both enwp and dewp.\n') + if superfluous % 100 == 99: + archiveNum = superfluous / 100 + wikipedia.Page(enwp,'User:VIAFbot/Superfluous/' + str(archiveNum)).append( last100LogLinesAsString(superfluouslog), comment='Logging', minorEdit=True, section=0) + else: pass """10- nd, ac, nd == ac != vl. requires human attention. Nothing written.""" if casenum == 10: - archiveNum = conflict10 / 100 - wikipedia.Page(enwp,'User:VIAFbot/Conflict/10/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' requires human attention: nd == ac != vl . VIAF number: ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - conflict10 = conflict10 + 1 + conflict10 += 1 + conflict10log.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' requires human attention: nd == ac != vl . VIAF number: ' + str(viafnum)) + if conflict10 % 100 == 99: + archiveNum = conflict10 / 100 + wikipedia.Page(enwp,'User:VIAFbot/Conflict/10/' + str(archiveNum)).append(last100LogLinesAsString(conflict10log), comment='Logging', minorEdit=True, section=0) + else: pass """11- nd, ac, nd != ac, nd == vl. requires human attention. Nothing written.""" if casenum == 11: - archiveNum = conflict11 / 100 - wikipedia.Page(enwp,'User:VIAFbot/Conflict/11/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' requires human attention: nd != ac, nd== vl . VIAF number: ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - conflict11 = conflict11 + 1 + conflict11 += 1 + conflict11log.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' requires human attention: nd != ac, nd == vl . VIAF number: ' + str(viafnum)) + if conflict11 % 100 == 99: + archiveNum = conflict11 / 100 + wikipedia.Page(enwp,'User:VIAFbot/Conflict/11/' + str(archiveNum)).append(last100LogLinesAsString(conflict11log), comment='Logging', minorEdit=True, section=0) + else: pass """12- nd, ac, nd != ac, ac == vl. requires human attention. Nothing written.""" if casenum == 12: - archiveNum = conflict12 / 100 - wikipedia.Page(enwp,'User:VIAFbot/Conflict/12/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' requires human attention: nd != ac, ac == vl . VIAF number: ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - conflict12 = conflict12 + 1 + conflict12 += 1 + conflict12log.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' requires human attention: nd != ac, ac == vl . VIAF number: ' + str(viafnum)) + if conflict12 % 100 == 99: + archiveNum = conflict12 / 100 + wikipedia.Page(enwp,'User:VIAFbot/Conflict/12/' + str(archiveNum)).append(last100LogLinesAsString(conflict12log), comment='Logging', minorEdit=True, section=0) + else: pass """13- nd, ac, nd != ac != vl. requires human attention. Nothing written.""" if casenum == 13: - archiveNum = conflict13 / 100 - wikipedia.Page(enwp,'User:VIAFbot/Conflict/13/' + str(archiveNum)).append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' requires human attention: nd != ac != vl . VIAF number: ' + str(viafnum), comment='Logging', minorEdit=True, section=0) - conflict13 = conflict13 + 1 + conflict13 += 1 + conflict13log.write('* ' + timestamp + ' . ' + validatedPage.title(asLink=True) + ' requires human attention: nd != ac != vl . VIAF number: ' + str(viafnum)) + if conflict13 % 100 == 99: + archiveNum = conflict13 / 100 + wikipedia.Page(enwp,'User:VIAFbot/Conflict/13/' + str(archiveNum)).append(last100LogLinesAsString(conflict13log), comment='Logging', minorEdit=True, section=0) + else: pass except exceptions.LockedPage: - raise exceptions.LockedPage + viafbotrun.write(timestamp + validatedPage.title() + ' log page gave locked page error \n') except exceptions.PageNotSaved: - raise exceptions.LockedPage + viafbotrun.write(timestamp + validatedPage.title() + ' log page gave page not saved error \n') except exceptions.EditConflict: - raise exceptions.EditConflict + viafbotrun.write(timestamp + validatedPage.title() + ' log page gave gave edit conflict error \n') except exceptions.SpamfilterError: - raise exceptions.SpamfilterError + viafbotrun.write(timestamp + validatedPage.title() + ' log page gave spam filter error \n') except exceptions.LongPageError: - raise exceptions.LongPageError + viafbotrun.write(timestamp + validatedPage.title() + ' log page gave long page error \n') + +def last100LogLinesAsString(logfile): + """Retruns the last 100 (or remainder if log has less than 100 lines) of a log as string""" + wikitext = '' + loglist = logfile.readlines() + if len(loglist) < 100: + pass + else: + loglist = loglist [-100:] + print + for i in range(0,len(loglist)): + wikitext += loglist[i] + return wikitext + +def writeLogTails(): + """Writing the last parts of the log that were batched but not writen""" + + def writeEntireTemplate(validatedPage, viafnum): """Uses add_text.py to add the wikitext of {{Authority control}} template with the VIAF parameter""" - global lockedError - global editConflictError - global spamfilterError - global pageNotSavedError - timestamp = strftime("%H:%M, %d %B %Y", gmtime()) ACtemplateWithVIAF = '\n{{Authority control|VIAF=' + str(viafnum) + '}}\n' editSummary = 'Added the {{Authority control}} template with VIAF number ' + str(viafnum) + '.' try: - add_text(page = validatedPage, + add_text_customised.add_text(page = validatedPage, addText = ACtemplateWithVIAF, always = True, #so add_text won't ask for confirmation summary = editSummary) except exceptions.LockedPage: - lockedError += 1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/Locked').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was locked when VIAFbot tried to edit it', comment='Logging', minorEdit=True, section=0) + raise exceptions.LockedPage except exceptions.EditConflict: - editConflictError += 1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/EditConflict').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' involved in an edit conflict when VIAFbot tried to edit it', comment='Logging', minorEdit=True, section=0) + raise exceptions.EditConflict except exceptions.ServerError: - pass + viafbotrun.write("writeEntireTemplate on page " + validatedPage.title() + ' gave generic server error.\n') except exceptions.SpamfilterError: - spamfilterError += 1 - wikipedia.Page(enwp,'Creating User:VIAFbot/Errors/Spamfilter').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was detected as a spam edit', comment='Logging', minorEdit=True, section=0) + raise exceptions.SpamfilterError except exceptions.PageNotSaved: - pageNotSavedError +=1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/PageNotSaved').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was not saved for some reason that is not editconflict, spam or locked', comment='Logging', minorEdit=True, section=0) - + raise exceptions.PageNotSaved + -def writeVIAFparamOnly(validatedPage,viafnum): - """Instantiates and runs replace.py's ReplaceRobot class""" - global lockedError - global editConflictError - global spamfilterError - global pageNotSavedError - timestamp = strftime("%H:%M, %d %B %Y", gmtime()) - preloadingGen = [validatedPage] - replacements = [('{{Authority control' , '{{Authority control|VIAF=' + str(viafnum))] - editSummary = 'Adding VIAF parameter to Authority control with VIAF number ' + str(viafnum) - exceptions = [] - acceptall = True - allowoverlap = False - recursive = False - add_cat = None - sleep = None - titlefile = None - excoutfile = None - replaceBot = ReplaceRobot(preloadingGen, replacements, exceptions, acceptall, - allowoverlap, recursive, add_cat, sleep, editSummary, - titlefile, excoutfile) - try: - replaceBot.run() - except exceptions.LockedPage: - lockedError += 1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/Locked').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was locked when VIAFbot tried to edit it', comment='Logging', minorEdit=True, section=0) - except exceptions.EditConflict: - editConflictError += 1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/EditConflict').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' involved in an edit conflict when VIAFbot tried to edit it', comment='Logging', minorEdit=True, section=0) - except exceptions.ServerError: - pass - except exceptions.SpamfilterError: - spamfilterError += 1 - wikipedia.Page(enwp,'Creating User:VIAFbot/Errors/Spamfilter').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was detected as a spam edit', comment='Logging', minorEdit=True, section=0) - except exceptions.PageNotSaved: - pageNotSavedError +=1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/PageNotSaved').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was not saved for some reason that is not editconflict, spam or locked', comment='Logging', minorEdit=True, section=0) def writeVIAFparamOnly2(validatedPage,viafnum): """Uses the textlib method replaceExcept""" - global lockedError - global editConflictError - global spamfilterError - global pageNotSavedError - timestamp = strftime("%H:%M, %d %B %Y", gmtime()) + pageWikiText = validatedPage.get() replacementText = textlib.replaceExcept(pageWikiText, '{{Authority control' , '{{Authority control|VIAF=' + str(viafnum), exceptions=[], caseInsensitive=False, @@ -439,20 +479,15 @@ def writeVIAFparamOnly2(validatedPage,viafnum): try: validatedPage.put(newtext = replacementText, comment = 'Added VIAF number ' + str(viafnum) + ' to {{Authority control}} temaplte.', watchArticle = False , minorEdit=True, force=False, sysop=False, botflag=True, maxTries = 5) except exceptions.LockedPage: - lockedError += 1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/Locked').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was locked when VIAFbot tried to edit it', comment='Logging', minorEdit=True, section=0) + raise exceptions.LockedPage except exceptions.EditConflict: - editConflictError += 1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/EditConflict').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' involved in an edit conflict when VIAFbot tried to edit it', comment='Logging', minorEdit=True, section=0) + raise exceptions.EditConflict except exceptions.ServerError: - pass + viafbotrun.write("writeEntireTemplate on page " + validatedPage.title() + ' gave generic server error.\n') except exceptions.SpamfilterError: - spamfilterError += 1 - wikipedia.Page(enwp,'Creating User:VIAFbot/Errors/Spamfilter').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was detected as a spam edit', comment='Logging', minorEdit=True, section=0) + raise exceptions.SpamfilterError except exceptions.PageNotSaved: - pageNotSavedError +=1 - wikipedia.Page(enwp,'User:VIAFbot/Errors/PageNotSaved').append('\n\n' + timestamp + ' ' + validatedPage.title(asLink=True) + ' was not saved for some reason that is not editconflict, spam or locked', comment='Logging', minorEdit=True, section=0) - + raise exceptions.PageNotSaved def writeStats(): wikipedia.Page(enwp,'User:VIAFbot/Stats').put( '{| class="wikitable"\n\ @@ -539,3 +574,24 @@ def writeStats(): if (touched % 1000) == 0: writeStats() else: pass + +writeLogTails() + +#close files +wikilinksfile.close() +viafbotrun.close() +NoDEWPlog.close() +YesDEWPlog.close() +conflict4log.close() +conflict6log.close() +conflict8log.close() +conflict10log.close() +conflict11log.close() +conflict12log.close() +conflict13log.close() +superfluouslog.close() +lockedErrorlog.close() +editConflictErrorlog.close() +pageNotSavedErrorlog.close() +spamfilterErrorlog.close() +longPageErrorlog.close()