From f35131991bc8b1aa87af0c9b1ba13bf53ab41f24 Mon Sep 17 00:00:00 2001 From: notconfusing Date: Mon, 6 Aug 2012 16:14:01 -0700 Subject: [PATCH] pagevalidator gets noPage exception handling --- viafbot.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/viafbot.py b/viafbot.py index c7a2020..84e8d75 100644 --- a/viafbot.py +++ b/viafbot.py @@ -10,17 +10,22 @@ # global variables enwp = getSite('en','wikipedia') dewp = getSite('de','wikipedia') - - +wikilinks = open("wikilinksforbot.out") +wikilinks = wikilinks.readlines() +viafbotrun = ("viafbotrun.log", 'w+') +#helper methods def pageValidator(nameOfPage): - """returns a string of either a page if it's valid""" + """returns a string of either the page or it's redirect (does not check double redirects). + Or returns None if the page does not exist""" namepage = Page(enwp, nameOfPage) try: namepage.get() except IsRedirectPage, redirPageName: return redirPageName + except NoPage, errorlist: + return None else: return nameOfPage @@ -37,3 +42,29 @@ def determineAuthorityControlTemplate(nameOfPage): return 'templateNoVIAF' return 'noACtemplate' + +#the main loop +same = 0 +total = 0 +nopage = 0 +linkvalidity = open('wikilinkvalidity.txt', 'w+') +linkvalidity.write('total,same, nopage' + '\n') +for wikilink in wikilinks: + wikilink = wikilink.split() + origNameOfPage = wikilink[0] + afternameOfPage = pageValidator(origNameOfPage) + print origNameOfPage, afternameOfPage + total = total +1 + if afternameOfPage == None: + nopage= nopage +1 + viafbotrun.write("No such article as " + origNameOfPage) + else: + pass + if origNameOfPage == afternameOfPage: + same = same +1 + else: + pass + linkvalidity.write( str(total) + " " + str(same) + str(nopage) + '\n') + +#close resources +wikilinks.close() \ No newline at end of file