Created
August 21, 2013 13:48
-
-
Save ghing/6294666 to your computer and use it in GitHub Desktop.
Get the average length (in characters) of published text assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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