Skip to content

Instantly share code, notes, and snippets.

@ghing
Created August 21, 2013 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghing/6294666 to your computer and use it in GitHub Desktop.
Save ghing/6294666 to your computer and use it in GitHub Desktop.
Get the average length (in characters) of published text assets
from django.utils.html import strip_tags
from storybase_asset.models import HtmlAsset
assets = HtmlAsset.objects.filter(stories__status='published')
total_length = 0
for asset in assets:
# Strip HTML from the body to more accurately reflect visible length
total_length += len(strip_tags(asset.body))
avg_length = total_length / assets.count()
print "%f" % avg_length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment