Skip to content

Instantly share code, notes, and snippets.

@inky
Last active August 29, 2015 14:01
Show Gist options
  • Save inky/094d5808e4c59807d15e to your computer and use it in GitHub Desktop.
Save inky/094d5808e4c59807d15e to your computer and use it in GitHub Desktop.
import re
import sys
GUTENBERG_START = re.compile(r'\*\*\*.*START.*PROJECT GUTENBERG')
GUTENBERG_END = re.compile('End of.*Project Gutenberg')
def parse_gutenberg(fp):
for line in fp:
if GUTENBERG_START.match(line):
break
for line in fp:
line = line.strip()
if GUTENBERG_END.match(line):
break
elif line:
yield line
if __name__ == '__main__':
for line in parse_gutenberg(sys.stdin):
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment