Skip to content

Commit

Permalink
pagevalidator gets noPage exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
notconfusing committed Aug 6, 2012
1 parent 7673cd1 commit f351319
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions viafbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

0 comments on commit f351319

Please sign in to comment.