Skip to content

Instantly share code, notes, and snippets.

@jaroel
Created January 27, 2012 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaroel/1688278 to your computer and use it in GitHub Desktop.
Save jaroel/1688278 to your computer and use it in GitHub Desktop.
Count words in Plone html
catalog = context.portal_catalog
lexicon = catalog.htmlwordsplitter_lexicon
brains = catalog(Language='nl', portal_type='CoolPage')
words = dict(Title=0, Description=0, getText=0)
for brain in brains:
ob = brain.getObject()
words['Title'] = ob.Title().split()
words['Description'] = ob.Description().split()
words['getText'] = lexicon.parseTerms(ob.getText())
no_of_words = len(words['Title']) + len(words['Description']) + len(words['getText'])
print ";".join(map(str, ['"%s"' % ob.Title(), ob.absolute_url(), len(words['Title']), len(words['Description']), len(words['getText']), no_of_words]))
return printed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment