from WikiPlugin import * from AppData import * import string import StringIO def getName(): # # This is the name that appears on the 'plugin' menu. # It should be unique # return "Lesson 03 - Page Access" def getVendorName(): # # The name of the person who developed the plugin # return "Dogmelon" def getVendorVersionString(): # # A version string for this plugin # return "1.0" def getDescription(): # # A brief, helpful description of the plugin # return "Lesson 02 - Read the contents of pages within a book." def preExecute(): # # Do anything you need to do before running the plugin. # This could include popping up a dialog to collect parameters. # returns a list of parameters, which will be passed to the execute() method # STAGE_NAME = "preExecute" return [] def writeBookHeader( outputFile, book ): bookName = book.getDisplayName() outputFile.write( "====================================\n" ) outputFile.write( "Book: '%s'\n"%(bookName) ) def searchPageForText( outputFile, page ): # We're looking on each page for the text "wookie" # If we find it, we're going to count how many different # lines we found it on. rawText = page.getText() if string.find( rawText, "wookie" ) == -1: outputFile.write( "does NOT contain 'wookie'\n" ) else: outputFile.write( "DOES contain 'wookie' - " ) stringStream = StringIO.StringIO( rawText ) pageLines = stringStream.readlines() count = 0 for line in pageLines: if string.find( line, "wookie" ) != -1: count = count + 1 outputFile.write( "found it on %d different lines\n"%(count) ) def writePageSummary( outputFile, book ): outputFile.write( "Page List:\n" ) numPages = book.getNumPages() for i in range( numPages ): pageName = book.getPageName( i ) outputFile.write( "%d, '%s' - "%(i, pageName) ) page = book.getPage( i ) searchPageForText( outputFile, page ) def doLesson3( outputFile ): numBooks = theAppData.library.getNumBooks() for i in range( numBooks ): book = theAppData.library.getBook( i ) writeBookHeader( outputFile, book ) writePageSummary( outputFile, book ) def execute( parameterList ): # # Here is where you actually do the plugin tasks. # # If anything goes wrong, you can throw a WikiPluginException # as follows: # STAGE_NAME = "execute" bThrowException = False outputFile = open( "C:/lesson03.txt", "w" ) outputFile.write( "Lesson 03\n\n" ) doLesson3( outputFile ) outputFile.close() if bThrowException: raise WikiPluginException( STAGE_NAME, "Some error string describing the problem" ) def postExecute(): # # Do anything you need to clean up after running the plugin. # STAGE_NAME = "postExecute" pass