Skip to content

Instantly share code, notes, and snippets.

@benjamingeiger
Created February 5, 2013 21:19
Show Gist options
  • Save benjamingeiger/4717754 to your computer and use it in GitHub Desktop.
Save benjamingeiger/4717754 to your computer and use it in GitHub Desktop.
import re
# Get a list of all stories. (This will have to be written at some point.)
stories = get_stories()
for story in stories:
summary = story.get_summary()
body = story.get_body()
if (not summary) or len(summary.trim()) == 0:
# Grab the first line of the body
graf = body[0]
# Replace the location (assumed to be in all caps and followed
# by a single vertical bar) and all space immediately following it
graf = re.sub(r"[A-Z,. ]+|\s*", "", graf, count=1)
# Truncate the line to 50 characters
graf = graf[:50]
# Add "..." to the end
graf += "..."
summary = graf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment