Databases Reference
In-Depth Information
def getInt(options, field, default):
try:
return int(options.get(field, default))
except Exception, e:
#raise a user friendly exception
raise Exception("%s must be an integer" % field)
#our main method, which reads the options, creates a WordCounter
#instance, and loops over the results
if __name__ == '__main__':
try:
#get our results
results, dummyresults, settings = si.getOrganizedResults()
keywords, options = si.getKeywordsAndOptions()
word_counter = WordCounter()
word_counter.mincount = getInt(options, 'mincount', 50)
word_counter.minwordlength = getInt(options,
'minwordlength', 3)
#determine whether we should be case sensitive
casesensitive = options.get('casesensitive', False)
if casesensitive:
casesensitive = (casesensitive.lower().strip() in
['t', 'true', '1', 'y', 'yes'])
word_counter.casesensitive = casesensitive
#loop through the original results
for r in results:
word_counter.process_event(r['_raw'])
output = word_counter.build_rows()
si.outputResults(output)
#catch the exception and show the error to the user
except Exception, e:
import traceback
stack = traceback.format_exc()
si.generateErrorResults("Error '%s'. %s" % (e, stack))
 
Search WWH ::




Custom Search