Last active
August 29, 2015 14:01
-
-
Save inky/094d5808e4c59807d15e to your computer and use it in GitHub Desktop.
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
| 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