Created
February 5, 2013 21:19
-
-
Save benjamingeiger/4717754 to your computer and use it in GitHub Desktop.
This file contains 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
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